请帮助我解决数据表示的问题。
我有一些 SQL 脚本,它创建以下数据表示:
Declare params cursor for
Select distinct id_variable from [UIR_DB].[dbo].[Variable_Values]
open params
Declare @idparam int
Declare @csql nvarchar(max) = ''
Declare @csql2 nvarchar(max) = ''
declare @csq13 nvarchar(max) = ''
Declare @i int = 1
fetch next from params into @idparam
while @@FETCH_STATUS = 0
begin
Select @csql2 = @csql2 +', id_var'+LTRIM(Str(@i))+ ', param' +LTrim(Str(@i))
Select @csql = ' (Select id_variable as id_var'+LTrim(Str(@i))+', value as param'+LTrim(Str(@i))+' from
[UIR_DB].[dbo].[Variable_Values] where id_variable = '+LTrim(Str(@idparam))+') a'+LTrim(Str(@i))+'
cross join'+@csql
Set @i = @i+1
fetch next from params into @idparam
end
Select @csql = 'Select '+SubString(@csql2,2,LEN(@csql2)-1)+' from
'+SubString(@csql,1,LEN(@csql)-11)+'order by'+SubString(@csql2,2,LEN(@csql2)-1)
print @csql
exec sp_executesql @csql
close params
deallocate params
我对 SQL 的了解还不是很远,所以请,如果它不是一个大问题,我需要脚本,它将从 Script1 结果创建下一个数据表示: