title: Passing a varchar type parameter and using it in set @SQL
body: <p>I have a stored procedure that has this line:</p>
  
  <pre><code>SET @SQL = 'SELECT path,title,tags
              FROM (
                    SELECT ROW_NUMBER() OVER(ORDER BY file_number) AS Row, *
                    FROM  files) AS tbl 
              WHERE file_number IN (SELECT tag_file_number 
                                    FROM tags 
                                    WHERE tag LIKE ' + @Conditions + '), Row &gt;= '
                     + CONVERT(varchar(9), @StartIdx) + ' AND
                     Row &lt;= ' + CONVERT(varchar(9), @EndIdx)
  </code></pre>
  
  <p>I get an error when I pass 'bus' as a parameter value. My objective is to pass a piece of SQL query and substitute it in the place of <code>@conditions</code>. </p>
  
  <p>I may also pass '%bu% or tag Like %time% or tag Like %bus time%' I think this is not hard to do but I simply can't figure it out. It's a very specific problem, therefore I can't even google it up. Please help me. Let me know if you need any more information. </p>