6

次のエラーが表示されます。

メッセージ 203、レベル 16、状態 2、プロシージャ getQuestion、行 18
The name '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

これを試してください。execute @query を execute (@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 に答える