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
 Use of Case Statements.

Author  Topic 

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-23 : 02:27:09
hi,
I want to know how can i equate the following case statements into
one Condition? Following is my Code


(case when ws.Action_Taken_ID not in(3,17,18) then '-1' else '0' end) as istechfcr,
(case when datediff(day,dbo.Usp_Get_Date(pr.Set_Serial_Number),oh.WO_Record_Date) <= q.Product_Gurantee_Months + 6 then '-1' else '0' end) as istechfcr,
(case when substring(ltrim(rtrim(ws.Symptom)),1,1) not in('X') then '-1' else '0' end) as istechfcr,
(case when ws.Action_Taken_ID not in(8,15,21,25) then '-1' else '0' end) as istechfcr,



Thanks..

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-07-23 : 02:31:49
It is based on your business requirement, how you want to get the data...
Here the return value is either -1 or 0, when you want to get -1 or zero with respect to AND/OR?

--------------------------------------------------
S.Ahamed
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-23 : 02:32:10
[code]SELECT case
when ws.Action_Taken_ID not in (3, 17, 18) then '-1'
when datediff(day, dbo.Usp_Get_Date(pr.Set_Serial_Number), oh.WO_Record_Date) <= q.Product_Gurantee_Months + 6 then '-1'
when substring(ltrim(rtrim(ws.Symptom)), 1, 1) not in ('X') then '-1'
when ws.Action_Taken_ID not in (8, 15, 21, 25) then '-1'
else '0'
end as istechfcr
from table1[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-23 : 02:34:46
[code]SELECT case
when ws.Action_Taken_ID not in (3, 8, 15, 17, 18, 21, 25) then '-1'
when datediff(day, dbo.Usp_Get_Date(pr.Set_Serial_Number), oh.WO_Record_Date) <= q.Product_Gurantee_Months + 6 then '-1'
when substring(ltrim(rtrim(ws.Symptom)), 1, 1) not in ('X') then '-1'
else '0'
end as istechfcr
from table1[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-23 : 02:47:04
Thanks for the Reply.

But Could you just let me Know if this will check for all individual Conditions?
ie As per my requirement if all Three conditions satisfies only then it should be -1
else 0.
Please Clarify..
Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-07-23 : 02:55:54
If you want all three condition to be satisfied then u need to put the AND condition...
Always try and check whether it is working

SELECT case
when ws.Action_Taken_ID not in (3, 8, 15, 17, 18, 21, 25) and
datediff(day, dbo.Usp_Get_Date(pr.Set_Serial_Number), oh.WO_Record_Date) <= q.Product_Gurantee_Months + 6 and
substring(ltrim(rtrim(ws.Symptom)), 1, 1) not in ('X') then '-1'
else '0'
end as istechfcr
from table1



--------------------------------------------------
S.Ahamed
Go to Top of Page

roxcy
Yak Posting Veteran

58 Posts

Posted - 2007-07-23 : 03:07:08
Thanks a Lot...
Go to Top of Page
   

- Advertisement -