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 |
|
Velnias
Yak Posting Veteran
58 Posts |
Posted - 2008-10-29 : 12:24:49
|
| Hey Guys,I was using the following query to between two dates which was more recent and use this value to determine if the date occured in the last 30 mins. WHERE (CASE WHEN dateAdded > dateLastModified THEN dateAdded ELSE dateLastModified END >= DATEADD(minute, - 60, GETDATE()))But however I found If dateLastModified field was empty, it would use dateLastModified and not dateAdded, how can I resolve this around empty fields.THanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-29 : 12:28:08
|
| [code]WHERE (CASE WHEN dateAdded > dateLastModified OR NULLIF(dateLastModified,'') IS NULL THEN dateAdded ELSE dateLastModified END >= DATEADD(minute, - 60, GETDATE()))[/code] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-30 : 02:58:10
|
| Avoid using CASE expression in WHERE caluse. You can tryWHERE (dateAdded > dateLastModified and dateAdded>= DATEADD(minute, - 60, GETDATE()))or (dateAdded <= dateLastModified and dateLastModified >= DATEADD(minute, - 60, GETDATE()))MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-30 : 03:45:57
|
quote: Originally posted by madhivanan Avoid using CASE expression in WHERE caluse. You can tryWHERE (dateAdded > dateLastModified and dateAdded>= DATEADD(minute, - 60, GETDATE()))or (dateAdded <= dateLastModified and dateLastModified >= DATEADD(minute, - 60, GETDATE()))MadhivananFailing to plan is Planning to fail
any special reason for that Madhi? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-30 : 04:58:26
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan Avoid using CASE expression in WHERE caluse. You can tryWHERE (dateAdded > dateLastModified and dateAdded>= DATEADD(minute, - 60, GETDATE()))or (dateAdded <= dateLastModified and dateLastModified >= DATEADD(minute, - 60, GETDATE()))MadhivananFailing to plan is Planning to fail
any special reason for that Madhi?
Performance issueMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-30 : 05:09:13
|
Ok...Thanks |
 |
|
|
|
|
|
|
|