Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Incorrect syntax near the keyword 'case'.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

9 Posts

Posted - 10/04/2012 :  02:46:33  Show Profile  Reply with Quote
Can someone please let me know whats wrong in the query given below

declare @strPmtModeId varchar(10),
@LeftInt Smallint,
@RightInt Smallint

set @strPmtModeId = '1,18'
set @LeftInt = Convert(Smallint,Left(@strPmtModeId,1))
set @RightInt = Convert(Smallint,Right(@strPmtModeId,2))

select * from tbl_Pmt_Mode
where (isnull(Pmt_Mode_Id,99) in
when Convert(SmallInt,Len(@strPmtModeId)) > 2
Convert(SmallInt,@strPmtModeId) is null)
(Convert(SmallInt,@strPmtModeId))) or Convert(SmallInt,@strPmtModeId) is null)


Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/04/2012 :  07:06:03  Show Profile  Reply with Quote
I didn't quite follow the logic you are trying to implement, but SQL Server does not like the way you are using the case expression. Perhaps something like this?
	( CONVERT(SMALLINT, LEN(@strPmtModeId)) > 2 AND ISNULL(Pmt_Mode_Id, 99) IN (@LeftInt, @RightInt) )
	@strPmtModeId IS NULL 
	--- OR ???
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 10/04/2012 :  10:49:54  Show Profile  Reply with Quote
i think all of your conditions can be simplified into below

where ',' + @strPmtModeId + ',' like '%,' + cast(isnull(Pmt_Mode_Id,99) as varchar(3)) + ',%' 
or @strPmtModeId  is null

SQL Server MVP

Go to Top of Page

Flowing Fount of Yak Knowledge

2916 Posts

Posted - 10/05/2012 :  08:55:47  Show Profile  Reply with Quote
a) the IN clause needs to be followed by ()
b) the CASE statement is not terminated properly. The ELSE portion is outside of a pair of brackets.
c) the OR clause also seems to be in the wrong place....especially in relation to the CASE statement.

start with a simple condition and then work upwards adding more complexity as you go along. it looks like you wrote it all in one go and misplaced some brackets.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000