i need to use a case statement in my sql, but i keep getting "Incorrect syntax near '='". anyone know what is the correct way to do so?? CompIM is my table field name, if the @CompFilt=2, i need to select those data with sso
declare @CompFilt
set @CompFilt = 2
select *
From MasterComponentTbl
where CompCountry = "UK"
and case when @CompFilt = 2 then CompIM = 'sso' else CompIM = 'TBA'
SELECT FirstName, LastName, TelephoneNumber, 'When to Contact' =
CASE
WHEN TelephoneSpecialInstructions IS NULL THEN 'Any time'
ELSE TelephoneSpecialInstructions
END
FROM Person.vAdditionalContactInfo;
Darrell Norton, MVP
Darrell Norton's Blog Please click "Mark as Answer" if this helped you.
Member
92 Points
406 Posts
sql select with case
Jun 02, 2010 04:35 AM|aoshi_kh|LINK
i need to use a case statement in my sql, but i keep getting "Incorrect syntax near '='". anyone know what is the correct way to do so?? CompIM is my table field name, if the @CompFilt=2, i need to select those data with sso
declare @CompFilt
set @CompFilt = 2
select *
From MasterComponentTbl
where CompCountry = "UK"
and case when @CompFilt = 2 then CompIM = 'sso' else CompIM = 'TBA'
All-Star
43204 Points
10243 Posts
MVP
Re: sql select with case
Jun 02, 2010 08:20 AM|DarrellNorton|LINK
You have no "END" statement. See the docs:
http://msdn.microsoft.com/en-us/library/ms181765.aspx
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
Member
92 Points
406 Posts
Re: sql select with case
Jun 02, 2010 08:44 PM|aoshi_kh|LINK
how if the else i need show other value than sso?? else in... i get error after else
declare @CompFilt
set @CompFilt = 2
select *
From MasterComponentTbl
where CompCountry = "UK"
and CompIM = case when @CompFilt = 2 then 'sso' else in (alt, TBA, sent)
Member
92 Points
406 Posts
Re: sql select with case
Jun 02, 2010 10:05 PM|aoshi_kh|LINK
anyone please help.. i was totally run out of idea. Thanks
Member
92 Points
406 Posts
Re: sql select with case
Jun 03, 2010 01:14 AM|aoshi_kh|LINK
finally solve it. i create dynamic var and use of if.. else.. statement to solve it. thanks