Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using this query to insert but getting syntax errors ...


SQL
insert into #tmp1
select strcallDi,
case when strcallDi=A
then strDescrip='Origi'
case when strcallDi=b
then strDescrip='Termi'
case when strcallDi=c
then strDescrip='Inco'
case when strcallDi=d
then strDescrip='Outg'
else
unknown
end
from (Select distinct strcallDi From B) As A
Where strcallDi not in (Select strCallDirection From dbo.#tmp1)


Help
Posted

1 solution

you're repeating the keyword case

The following is how you use case

SQL
SELECT CASE WHEN ColumnA = 1 THEN 'A' WHEN ColumnA = 2 THEN 'B' ELSE 'C' END


Although if you're only checking a single value and not multiple expressions the following is also valid.

SQL
SELECT CASE ColumnA WHEN 1 THEN 'A' WHEN 2 THEN 'B' ELSE 'C' END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900