I am stumped on an output query. I feel unpivot will get me there but I can't seem to get the syntax correct and could use some help. Basically, a single record set contains two columns and one column is actually the column name while the other column is the column value. Ideally I would like the output to label column 2 as column 1's result for each possible unique value. Below is a simplified sample but the final solution could contain an infinite number of attributes per pc.
create table #t (pc int, attribute varchar(100), result varchar(100) )
go
INSERT INTO #t VALUES (1,'OS','LINUX'),(1,'VERSION','10.4'),(2,'OS','WINDOWS'),(2,'VERSION','10.1903'),(3,'OS','LINUX'),(3,'VERSION','11.0'),(4,'OS','WINDOWS'),(4,'VERSION','10.1909'),(5,'OS','WINDOWS'),(5,'VERSION','10.1909'),(6,'OS','LINUX'),(6,'VERSION','10.4')
go
select * from #t
Result Set:
id pc attribute result
1 OS LINUX
1 VERSION 10.4
2 OS WINDOWS>
2 VERSION 10.1903
3 OS LINUX
3 VERSION 11.0
4 OS WINDOWS
4 VERSION 10.1909
5 OS WINDOWS
5 VERSION 10.1909
6 OS LINUX
6 VERSION 10.4
Desired Output:
pc OS VERSION
1 LINUX 10.4
2 WINDOWS 10.1903
3 LINUX 11.0
4 WINDOWS 10.1909
5 WINDOWS 10.1909
6 LINUX 10.4
Any tips/advice you can give would be greatly appreciated. Cheers mate.
question from:
https://stackoverflow.com/questions/65886819/dynamic-select-statement-to-convert-recordset-into-a-readable-format 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…