求助。。。。。关于sql问题
耿俊才(耿俊才) 10:36:45
declare @i int
set @i=1
while @i<27
begin
declare @a nvarchar(20)
declare @b nvarchar(20)
declare @sql nvarchar(200)
select @b=timespk from tbs
where showorder=@i
select @a=tbname from tbs
where showorder=@i
SET @sql='SELECT max('+@b+') FROM '+@a
exec (@sql)
exec sql update tbs
set maxt=@sql---- 传递不过来
where showorder=@i
set @i=@i+1
end
------解决方案-------------------- EXEC (@sql)之后就释放了,所以你后面用不了的,
------解决方案--------------------
declare @i int
set @i=1
while @i<27
begin
declare @a nvarchar(20)
declare @b nvarchar(20)
declare @sql nvarchar(200)
select @b=timespk from tbs
where showorder=@i
select @a=tbname from tbs
where showorder=@i
SET @sql='SELECT max('+@b+') FROM '+@a
exec (@sql)
EXEC('update tbs
set maxt=('+@sql+')
where showorder='+LTRIM(@i)
)set @i=@i+1
end
猜想楼主应该是这意思吧