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.
| Author |
Topic |
|
johnstern
Yak Posting Veteran
67 Posts |
Posted - 2007-06-20 : 11:08:51
|
| I am trying to get a 0 or 1 value ( false/true) if a date is " younger" than 7 days here is my pseudo code (startDate is the column name) Select if (startDate >= GetDate() – 7)new = 1else new = 0 As NewRecFrom mytable what would be the correct syntax to accomplish this |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-20 : 11:15:51
|
You need to use CASE statement for this.Select case When startDate >= DateAdd(day, -7, GetDate()) then 1else 0 end As NewRecFrom mytable Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
charlie.snell
Starting Member
3 Posts |
Posted - 2007-06-20 : 11:22:18
|
| SELECT CASE WHEN (@STARTDATE >= (GETDATE()-7)) THEN 1 ELSE 0 END |
 |
|
|
charlie.snell
Starting Member
3 Posts |
Posted - 2007-06-20 : 11:26:33
|
| Is using DateAdd better / more standardised than the (getdate()-7) snippet in my sql snippet? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-21 : 10:12:35
|
| Set the execution plan and seeMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|