好象是:
declare @p1 varchar(100)set @p1='select top '+cast(@top as varchar)+' * from DTable where id='+@idexec(@p1)

解决方案 »

  1.   

    declare @cmd nvarchar(255)Set @cmd = 'select top ' + cast(@top as nvarchar) 
       + ' * from DTable where id=' + cast(@id as nvarchar)exec sp_executesql @cmd
      

  2.   

    搞错了。id为int要转化.declare @p1 varchar(100)set @p1='select top '+cast(@top as varchar)+' * from DTable where id='+cast(@id as varchar)exec(@p1)
      

  3.   

    搞错了。id为int要转化.呵呵.不好意思.declare @p1 varchar(100)set @p1='select top '+cast(@top as varchar)+' * from DTable where id='+cast(@id as varchar)exec(@p1)
      

  4.   

    exec('select top '+cast(@top as varchar)+' * from DTable where id='+cast(@id as varchar))
      

  5.   

    @id int,
    @top int
    @sql_str nvarchar(4000)
    set sql_str='select top '+cast(@top as nvarchar)+' * from DTable where id='+cast(@id as nvarchar)
    EXECUTE sp_executesql sql_str
      

  6.   

    declare @id int
    declare @top int
    declare @sql_str nvarchar(4000)
    set sql_str='select top '+cast(@top as nvarchar)+' * from DTable where id='+cast(@id as nvarchar)
    EXECUTE sp_executesql sql_str