This static query using a parameter returns one row:
DECLARE @sqltext nvarchar(max)
DECLARE @status varchar(100)
SET @status = 'Active: Complete'
select * from status where StatusTitle = @status and type_id = 800
However, using the parameter in a dynamic SQL query as follows does not return any rows at all:
SET @sqltext = 'SELECT s.StatusID
FROM [Status] s
WHERE (
( s.StatusTitle ='' + @status + '' )
AND s.[type_id] = 800 )'
EXECUTE sp_executesql @sqltext
I know there is something wrong with the WHERE clause. I can't figure out how to correct it.
AND s.[type_id] = 800
to the first static SQL and check if it still returns 1 row – Mach