How to get the result in 1 row? Employee table has the following data: Id Name Phone -------------- 1 Tom 2545667 2 Jack 3234342 How would I retreive these two records into one row like these: Id1 Name1 Phone1 Id2 Name2 Phone2 ---------------------------------- 1 Tom 2545667 2 Jack 3234342 Thank you.
Just for completeness. On SQL Server 2005 you should be able to achieve this by using the new APPLY() construct. -- Frank Kalis Microsoft SQL Server MVP http://www.insidesql.de Heute schon gebloggt?http://www.insidesql.de/blogs
quote:Originally posted by FrankKalis Just for completeness. On SQL Server 2005 you should be able to achieve this by using the new APPLY() construct. -- Frank Kalis Microsoft SQL Server MVP http://www.insidesql.de Heute schon gebloggt?http://www.insidesql.de/blogs Is that just like single command similar to PIVOT? Madhivanan Failing to plan is Planning to fail
Yes, a single command referencing a table-valued function. -- Frank Kalis Microsoft SQL Server MVP http://www.insidesql.de Heute schon gebloggt?http://www.insidesql.de/blogs
Thats cool. I hope that will handle more than 8000 characters as well Madhivanan Failing to plan is Planning to fail
SELECT * FROM (SELECT id AS id1, name AS name1, phone AS phone1 FROM Employee WHERE Id = 1) a CROSS JOIN (SELECT id AS id2, name AS name2, phone AS phone2 FROM Employee WHERE Id = 2) b
quote:Originally posted by alvin1 How to get the result in 1 row? Employee table has the following data: Id Name Phone -------------- 1 Tom 2545667 2 Jack 3234342 How would I retreive these two records into one row like these: Id1 Name1 Phone1 Id2 Name2 Phone2 ---------------------------------- 1 Tom 2545667 2 Jack 3234342 Thank you. What do you want to get if there are thosands of rows? Madhivanan Failing to plan is Planning to fail