日期:2014-05-19  浏览次数:20693 次

请问如何在存储过程中返回一个表变量呢?
CREATE   PROCEDURE   qqqq
@regh   table   (lotid   char(16))
  AS
declare   @gh   table   (lotid   char(16))

insert   into   @gh(lotid)   select   top   10     lotid   from   lot
select   *   from   @gh

上面会出现语法出错!

thanks



------解决方案--------------------

CREATE PROCEDURE qqqq
@regh table (lotid char(16))
AS
declare @gh table (lotid char(16))
declare @sql varchar(8000)

set @sql = 'insert into '+ @gh(lotid) + ' select top 10 lotid from lot ' --这个要用动态的sql语句

exec (@sql)
exec ( 'select * from '+@gh) --这个要用动态的sql语句