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 |
wembleybear
Yak Posting Veteran
93 Posts |
Posted - 2013-05-29 : 09:13:42
|
Hi everyoneI'm relatively new to SQL and wonder if someone can assist with what I'm trying to achieve in this query. I have re-used a SQL statement from elsewhere on this forum and it works OK. What I want to do now is modify it so that I get another result column which evaluates the result of the CASE statement and says if DaysAmount <=1 then "TRUE else if DaysAmount >2 then "FALSE". Can anyone help me with how to do this please - here is the code I have at the moment:select worknumber, date_in, est_complete_date, (DATEDIFF(dd, [date_in], [est_complete_date]))-(DATEDIFF(wk, [date_in], [est_complete_date]) * 2)-(CASE WHEN DATENAME(dw, [date_in]) = 'Sunday' THEN 1 ELSE 0 END)-(CASE WHEN DATENAME(dw, [est_complete_date]) = 'Saturday' THEN 1 ELSE 0 END)as DaysAmountfrom worksorderhdrwhere custnum like 'BARR%'Many thanksMartyn-----------------SQL Server 2008 |
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-05-29 : 10:06:31
|
[CODE]SELECT worknumber, date_in, est_complete_date,(CASE WHEN DaysAmount<= 1 THEN TRUE ELSE FALSE END) as DayLogicFROM (select worknumber, date_in, est_complete_date, (DATEDIFF(dd, [date_in], [est_complete_date]))-(DATEDIFF(wk, [date_in], [est_complete_date]) * 2)-(CASE WHEN DATENAME(dw, [date_in]) = 'Sunday' THEN 1 ELSE 0 END)-(CASE WHEN DATENAME(dw, [est_complete_date]) = 'Saturday' THEN 1 ELSE 0 END)as DaysAmountfrom worksorderhdrwhere custnum like 'BARR%') A[/CODE] |
|
|
wembleybear
Yak Posting Veteran
93 Posts |
Posted - 2013-05-29 : 10:12:12
|
Works perfectly! Very useful. Many thanks for your helpMartyn------------SQL Server 2008 |
|
|
|
|
|
|
|