Hi Guys,
I have simple query within stored proc which I'm trying to nail it, this code below is working
but when I try to put condition as below it doesn't work
I wonder where I did wrong?
Cheers
I have simple query within stored proc which I'm trying to nail it, this code below is working
Code:
DECLARE @Code nvarchar
SET @Code = '2D'
Select SYSTSClientID = c.SYST_CLNT_I,
Code = c._C,
ClientName = c.CLNT_M
From CLNT c (nolock),
CLNT_ULT_RISK cur (nolock)
Where c.SYST_STUS_C = ' '
AND c.SYST_CLNT_I = cur.SYST_CLNT_I
AND c._C like @Code + '%'
but when I try to put condition as below it doesn't work
Code:
DECLARE @Code nvarchar
SET @Code = '2D'
Select SYSTSClientID = c.SYST_CLNT_I,
Code = c._C,
ClientName = c.CLNT_M
From CLNT c (nolock),
CLNT_ULT_RISK cur (nolock)
Where c.SYST_STUS_C = ' '
AND c.SYST_CLNT_I = cur.SYST_CLNT_I
AND
CASE
WHEN @Code IS NOT NULL THEN c._C like @Code + '%'
ELSE @ClientName IS NOT NULL THEN c.CLNT_M like '%' + @ClientName + '%' END
Order By c._C
I wonder where I did wrong?
Cheers