When I run the following code without setting any parameters I get the desired output
SELECT * FROM (
SELECT [CaseNumber]
,[EventCode]
,[EventDate]
,[Assigned]
,ROW_NUMBER() OVER (
PARTITION BY CaseNumber
ORDER BY CaseNumber,EventDate DESC,EventCode
) AS [ROW NUMBER]
FROM [databasename].[dbo].[tblCsCaseEvents]
) groups
WHERE 1=1
AND (groups.[ROW NUMBER]=1) AND (Assigned IN ('PARKERE'))
AND EventCode LIKE 'ba%'
However, when I declare and set variables as shown below and run it. The script doesn't seem to work. Why is that the case?
Declare @attorney CHAR (10)
Declare @event CHAR (10)
set @attorney='PARKERE'
set @event='ba%'
SELECT * FROM (
SELECT [CaseNumber]
,[EventCode]
,[EventDate]
,[Assigned]
,ROW_NUMBER() OVER (
PARTITION BY CaseNumber
ORDER BY CaseNumber,EventDate DESC,EventCode
) AS [ROW NUMBER]
FROM [databasename].[dbo].[tblCsCaseEvents]
) groups
WHERE 1=1
AND (groups.[ROW NUMBER]=1) AND (Assigned IN (@attorney))
AND EventCode LIKE @event