Last post Jan 24, 2018 08:28 AM by tridip1974
Jan 08, 2018 09:49 AM|tridip1974|LINK
table has id and name column and i need to display data as per the above fashion.
i use the below sql and it is working
CROSS APPLY (
('ID' , cast(ID as varchar)),
('[Name]' , Name)
) as CA (ID, Name)
just tell me how could i show the data as per my above fashion using pivot or unpivot instead of CROSS APPLY. help me with sample code.
Jan 20, 2018 06:18 AM|Deepak Panchal|LINK
I try to find a suitable example using unpivot but it looks like in newer version of SQL Cross Apply is the suitable approach to achieve your requirement.
So i suggest you to continue using Cross Apply.
Jan 24, 2018 08:28 AM|tridip1974|LINK
i sort the issue this way too
SELECT Result AS ID,Output AS Name
(SELECT CAST(ID AS VARCHAR(10)) AS ID,
CAST(Name AS VARCHAR(10)) as Name
FROM Emp2) stu
(Output FOR Result IN (ID, Name)
) AS mrks
does with union
SELECT CAST(id as varchar(20)) AS [Output],id as keyval,1 as sortord
SELECT name, id, 2
ORDER BY key