1

我有一个包含这一行的存储过程:

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 >= '
                   + CONVERT(varchar(9), @StartIdx) + ' AND
                   Row <= ' + CONVERT(varchar(9), @EndIdx)

当我将“总线”作为参数值传递时出现错误。我的目标是传递一段 SQL 查询并将其替换为@conditions.

我也可能通过'%bu% or tag Like %time% or tag Like %bus time%' 我认为这并不难做到,但我就是想不通。这是一个非常具体的问题,因此我什至无法搜索它。请帮我。如果您需要更多信息,请告诉我。

4

1 回答 1

1

您缺少引号,请像这样尝试:

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 >= '
                            + CONVERT(varchar(9), @StartIdx) + ' AND
               Row <=  ' + CONVERT(varchar(9), @EndIdx)

现在发生的事情是where tag like bus,而且必须是where tag like "bus"

于 2012-06-25T08:43:32.990 回答