You can not assign a value in the case
. Case
can only return a value.
You could use something like this instead.
declare @Key1 nvarchar(100)
declare @Key2 nvarchar(100)
declare @Key3 nvarchar(100)
declare @Key4 nvarchar(100)
select
@Key1 = P.Key1,
@Key2 = P.Key2,
@Key3 = P.Key3,
@Key4 = P.Key4
from
(
select left(col, CHARINDEX(':',col) - 1) as K,
right(col, Len(col) - CHARINDEX(':',col)) as V
from
( values
( 'Key1:Test1' ),
( 'Key2:Test2' ),
( 'Key3:Test3' ),
( 'Key4:Test4' ) ) as col ( col )
) as A
pivot (min(A.V) for A.K in (Key1, Key2, Key3, Key4)) as P