Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi All,I have data like this course_id Session--------- --------1234 8.00 - 10.004567 8.00 - 10.00From the above table i want the result to be like thiscourse_id1 course_id2 session---------- ---------- -------1234 4567 8.00 - 10.00Get someone get me a query to get the above result formatMadhavi
nagino
Yak Posting Veteran
75 Posts
Posted - 2014-04-18 : 05:45:02
SELECTT1.course_id course_id1,T2.course_id course_id2,T1.sessionFROM YourTable T1INNER JOIN YourTable T2ON T1.course_id < T2.course_idAND T1.Session = T2.Session-------------------------------------From JapanSorry, my English ability is limited.
Madhavi.extarc
Starting Member
7 Posts
Posted - 2014-04-18 : 06:01:46
thank u nagino. Madhavi
MuralikrishnaVeera
Posting Yak Master
129 Posts
Posted - 2014-04-18 : 06:15:21
Another way....
DECLARE @TEMP TABLE(course_id INT ,Session VARCHAR(MAX))INSERT INTO @TEMP VALUES(1234, '8.00 - 10.00'),(4567, '8.00 - 10.00')SELECT [1234] AS CourseID_1,[4567] AS CourseID_2,[SESSION] FROM @TEMP PIVOT( MAX(course_id) FOR course_id IN ([1234],[4567]))Pvt
---------------Murali KrishnaYou live only once ..If you do it right once is enough.......