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
 error while executing simple query :(

Author  Topic 

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2007-12-21 : 01:43:25
Hi,

I am using this query to execute but it didn't

declare @AccountID numeric(3,0)
set @AccountID = 101
select * from AccountTest
WHERE AccountID IN
(CASE
WHEN @AccountID = 101 THEN (100,101)
ELSE @AccountID
END)

I m getting error like

Msg 102, Level 15, State 1, Line 9
Incorrect syntax near ','.


Pls help me out

T.I.A

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-21 : 02:04:20
SELECT * FROM AccountTest
WHERE (@AccountID = 101 AND AccountID IN (100, 101))
OR @AccountID = AccountID



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-21 : 02:07:38
You cant put a variable as a value inside IN

Use like this

declare @AccountID numeric(3,0)
set @AccountID = 101
select * from AccountTest
WHERE (@AccountID = 101 AND AccountID IN (100,101))
OR (AccountID =@AccountID)
Go to Top of Page

under2811
Constraint Violating Yak Guru

366 Posts

Posted - 2007-12-21 : 02:11:08
Thanks u both :)

Gr8 Help :)
Go to Top of Page
   

- Advertisement -