How do I use Wildcards %% with dynamic SQL?
Posted on 2004-12-01
Good afternoon experts!
I need to use wild cards on the following Stored Procedure, on variable @strrequiredoptions. The column family may have several values for the same record. My sample shows how I do it for standard SQL. This does not return an error, but I get nothing returned, even if there is only 1 vale in the Family column.
CREATE PROCEDURE spGetReqOptionDetails
declare @SQL VARCHAR(8000)
declare @temp nvarchar(250)
set @temp = '%' + @strrequiredoptions + '%'
SET @SQL = 'select * from CMRC_Products WHERE family in (''' + Replace(@temp ,',',''',''') + ''') '