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
 General SQL Server Forums
 New to SQL Server Programming
 Greater than with date isn' working

Author  Topic 

sven2
Yak Posting Veteran

57 Posts

Posted - 2009-10-28 : 10:46:21
Hello,

when a date is greater than 01/01/05 I want to display an X ...
I tried the following code, but it didn't work:

SELECT Personeelsnummer, startdate, Enddate,
CASE Premies.startdate WHEN > 01 / 01 / 2005 THEN 'X' ELSE '' END AS Active
FROM dbo.Premies

What is wrong with this code?

Thanks in advance,
Sven.

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-10-28 : 10:49:08
what is the datatype of the field startdate ?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-28 : 10:49:35
If you mean greater than 01.01.2005 without regarding any timepart you can do this:
CASE WHEN Premies.startdate >= '20050102' THEN 'X' ELSE '' END AS Active



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sven2
Yak Posting Veteran

57 Posts

Posted - 2009-10-28 : 12:25:37
Hello,

thanks for the comment, the code like

CASE WHEN Premies.startdate >= '20050102' THEN 'X' ELSE '' END AS Active

is working just fine.

Now i was wondering is it possible to add the folowing code in the SQL:

DATEDIFF(week, startdate, enddatum) AS Weeks instead of the 'X'

So, something like this:

CASE WHEN Premies.startdate >= '20050102' THEN DATEDIFF(week, startdate, enddatum) ELSE '' END AS Weeks

Best regards,
Sven.


Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-28 : 12:31:44
Did you try it?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

naveengopinathasari
Yak Posting Veteran

60 Posts

Posted - 2009-10-28 : 14:16:16
Try this.

SELECT Personeelsnummer, startdate, Enddate,
CASE WHEN Premies.startdate > '01/01/2005' THEN 'X' ELSE '' END AS Active
FROM dbo.Premies

Lets unLearn
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-10-28 : 14:20:37
quote:
Originally posted by naveengopinathasari

Try this.

SELECT Personeelsnummer, startdate, Enddate,
CASE WHEN Premies.startdate > '01/01/2005' THEN 'X' ELSE '' END AS Active
FROM dbo.Premies

Lets unLearn


This problem was already solved!
Please read proper what OP wants now.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sven2
Yak Posting Veteran

57 Posts

Posted - 2009-10-28 : 15:44:34
Hello,

the problem with the datediff is also solved.

Thanks.

Sven.
Go to Top of Page
   

- Advertisement -