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
 In clause in where statement

Author  Topic 

ray03
Starting Member

1 Post

Posted - 2009-01-14 : 01:25:30
SELECT * FROM OLAPopportunities WHERE customer_id = 2 AND salesperson_id ='Thomas'
and case when iscos = '1' then
cos_id in (1,2,3,4,5,6,7,8,9)
else
status_id in(10,20,30,40,50,60,70,80,90,100)
end


AND Desc_Dim1=4
AND (convert(varchar(12),create_date,103)>='01/01/09' AND convert(varchar(12),create_date,103)<='19/01/09')


I am getting incorrect syntax near IN cluase.

How do i fix this

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-14 : 02:17:50
[code]SELECT * FROM OLAPopportunities WHERE customer_id = 2 AND salesperson_id ='Thomas'
and ((iscos = '1' and cos_id in (1,2,3,4,5,6,7,8,9) )
or (iscos <> '1' and status_id in(10,20,30,40,50,60,70,80,90,100))
)
AND Desc_Dim1=4
AND (convert(varchar(12),create_date,103)>='01/01/09' AND convert(varchar(12),create_date,103)<='19/01/09')
[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-14 : 03:03:45
[code]SELECT *
FROM olapOpportunities
WHERE Customer_ID = 2
AND Salesperson_ID = 'Thomas'
AND 1 = CASE
WHEN isCos = '1' AND Cos_ID IN (1, 2, 3, 4, 5, 6, 7, 8, 9) THEN 1
WHEN IsCos <> '1' AND Status_ID IN (10, 20, 30, 40, 50, 60, 70, 80, 90, 100) THEN 1
ELSE 0
END
AND Desc_Dim1 = 4
AND Create_Date >= '2009-01-01'
AND Create_Date < '2009-01-20'[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -