Hi all, I am trying to build some dynamic sql. The first bit works but cannot get the second to work? Any help appreciated.
adding new var @pWhereClause at the end gives error
How can I add the var @pWhereClause to the end of the sql?
Thx
Age is a consequence of experience
Code:
declare @pWhereClause VARCHAR(50);
set @pWhereClause = ' a.Visible = 1 AND a.Archived = 0 ' + @pWhereClause;
declare @recCount INT;
declare @sql NVARCHAR(500)
EXEC SP_EXECUTESQL N' select @recCount = count(*)
FROM [PomPomplingAddresses] a
LEFT JOIN [PomWebProperties] wp ON wp.PomplingAddressID = a.PomplingAddressID
LEFT JOIN PomRentalProperties prp ON prp.PomplingAddressID = wp.PomplingAddressID
LEFT JOIN [PomPropertyImages] ppi ON ppi.PomplingAddressID = a.PomplingAddressID AND ppi.IsMainImage = 1
', N'@recCount INT OUTPUT', @recCount OUTPUT
select @recCount
adding new var @pWhereClause at the end gives error
Code:
declare @pWhereClause VARCHAR(50);
set @pWhereClause = ' a.Visible = 1 AND a.Archived = 0 ' + @pWhereClause;
declare @recCount INT;
declare @sql NVARCHAR(500)
EXEC SP_EXECUTESQL N' select @recCount = count(*)
FROM [PomPomplingAddresses] a
LEFT JOIN [PomWebProperties] wp ON wp.PomplingAddressID = a.PomplingAddressID
LEFT JOIN PomRentalProperties prp ON prp.PomplingAddressID = wp.PomplingAddressID
LEFT JOIN [PomPropertyImages] ppi ON ppi.PomplingAddressID = a.PomplingAddressID AND ppi.IsMainImage = 1
@pWhereClause', N'@recCount INT OUTPUT', @recCount OUTPUT
select @recCount
How can I add the var @pWhereClause to the end of the sql?
Thx
Age is a consequence of experience