6

我收到以下错误:

消息 203,级别 16,状态 2,过程 getQuestion,第 18 行
名称 'select top(1) * from tlb_Question inner join tlb_options on tlb_options.qID=tlb_Question.id and tlb_Question.qNumber=1 and tlb_Question.id not in (0 ,1)' 不是有效的标识符

从以下存储过程:

ALTER proc getQuestion
    @qNo bigint,
    @total bigint,
    @next nvarchar(max)
as
begin 
    declare @hisa bigint
    set @hisa=@total/3

    if(@qNo<=@total/3)
    begin
    declare @query nvarchar(max)
    set @query=('select top(1) * from tlb_Question 
        inner join tlb_options on tlb_options.qID=tlb_Question.id and tlb_Question.qNumber=1 and tlb_Question.id not in ('+cast(@next as varchar)+')')
    print @query
    execute @query
    end
end
4

2 回答 2

21

请试试这个,将执行@query更改为执行(@query):

ALTER proc getQuestion
    @qNo bigint,
    @total bigint,
    @next nvarchar(max)
as

begin 
    declare @hisa bigint
    set @hisa=@total/3

    if(@qNo<=@total/3)
    begin
      declare @query nvarchar(max)
      set @query=('select top(1) * from tlb_Question 
      inner join tlb_options on tlb_options.qID=tlb_Question.id and tlb_Question.qNumber=1 and tlb_Question.id not in ('+cast(@next as varchar)+')')
      --print @query
      execute (@query)
    end
end
于 2012-11-03T04:24:15.680 回答
2

问题是execute @query。我可以在测试后确认。@techdo 是正确的。将其更改为

execute (@query)
于 2012-11-03T05:19:27.763 回答