Pass (Send) variable to Case statement in SQL Server query

Last Reply 29 days ago By dharmendr

Posted 29 days ago
select idpelamar,
case when jk='L' then 'Laki' when jk='P' then 'Perem' end as JENIS
from tblpelamar

it's work, so how to if 'case' statment make as variable like this

declare @jenis nvarchar(1)
declare @perintah nvarchar(100)
set @jenis='L'
set @perintah='case when jk=@jenis then Laki when jk=@jenis then Prem end as JENIS'
select idpelamar,
+@perintah
from tblpelamar

 

You are viewing reply posted by: dharmendr 29 days ago.
Posted 29 days ago