I have the following dynamic query which is working fine without the WHERE clause, which is expecting UNIQUEIDENTIFIER.
WHERE
UNIQUEIDENTIFIER
When I pass it in,
You must pass in the parameters to sp_executesql. See MSDN for details.
... WHERE CreatedBy = @p ... EXECUTE sp_executesql @sql, N'@p UNIQUEIDENTIFIER', @p = @p_CreatedBY