提示的错误是@MaxID 没有定义

解决方案 »

  1.   

    DECLARE @MaxID bigint
    DECLARE @temp nVARCHAR(4000)
    select  @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2'
    EXEC (@temp)
    exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
      

  2.   

    sorry,多了一句:
    DECLARE @MaxID bigint
    DECLARE @temp nVARCHAR(4000)
    select  @temp='SELECT @MaxID = max(id) from(SELECT TOP 200 id FROM (select * from testtable) as T9 ORDER BY id) as T2'
    exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output
      

  3.   

    要这么麻烦吗?DECLARE @MaxID bigint
    SELECT @MaxID = max(id) 
    from (SELECT TOP 200 id FROM testtable ORDER BY id
    ) as T2
      

  4.   

    exec sp_executesql @temp,N'@MaxID bigint output',@MaxID output