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 |
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2011-03-23 : 18:50:37
|
| HiI’ve been using this code to determine the number of days since the value in DateAssigned. Now the client wants to use DateReassigned if there is a value and if not continue to use DateAssigned. I thought I should use COALESCE(DateAssigned, DateReassigned) AS DaysSinceAssigned but I don’t know how to work the DATEDIFF function in there as well. CASEWHEN DateClosed IS NULL Then DATEDIFF(day, DateAssigned, GETDATE())WHEN DateClosed IS NOT NULL Then NULLEND AS DaysSinceAssigned, Bad Attempt:COALESCE(DATEDIFF(day, DateAssigned, GETDATE(), DATEDIFF(day, ReDateAssigned, GETDATE()) AS DaysSinceAssigned |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2011-03-23 : 19:06:10
|
| DateClosed is just any date e.g. '03/11/2011' and then I use DATEDIFF to calculate the number of days from today's date so DaysSinceAssigned value would be 12 for today. I want to use the DATEDIFF function over either DateReAssigned or DateAssigned (in that order) but not both.Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|