Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Date greater than less then, THEN ELSE

Author  Topic 

pcride
Starting Member

9 Posts

Posted - 2011-09-27 : 23:46:46
Hi, I have 2 date fields, need to compare them

If Date 1 >= Date 2, then 0, else 1

The result needs to be a new column added to my data set

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-28 : 00:03:08
use case when

select
.....
case when Date 1 >= Date 2 then 0 else 1 end as yournewcolumnname
....


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pcride
Starting Member

9 Posts

Posted - 2011-09-28 : 01:28:57
Thanks for the fast response.

I did this and it gives me

Incorrect syntax near the keyword case

does it have to be after the From DataBasename or after the WHERE clause?
Go to Top of Page

pcride
Starting Member

9 Posts

Posted - 2011-09-28 : 01:31:57
Never mind I got it.

Thanks again

If you could provide addtional assistance.

Now I need to divide that code with the total number of records in the same query result.

Would it be Sum (Case when?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-28 : 01:40:25
whats meaning of that? can you tell me what you're trying to calculte?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -