I am new to SQL Server and this is my first post.
I am getting the message "incorrect syntax near '=' when using the Case Statement. Here is an example of my code:
Select * , CASE
when a > b THEN b = a
when c > d THEN d = c
when e > f THEN f = e
when g > h THEN h = g
when i > j THEN j = i
when k > l THEN l = k
when m > n THEN n = m
when o > p THEN p = o
END as value
INTO #temptable
From #atemptable
Thanks in advance for your help!
It's not clear if you want the
THEN
part to be an assignment or a comparison. Either way, it's not possible, theTHEN
part can only be an expression. I'm assuming that you wanted an assignment. It looks that you don't want to update the#atemptable
, you just want the new values in#temptable
. In this case, you can use separateCASE
expressions, like this: