Friday, 16 December 2011

Select many rows as one row in SQL

In some situations we may need the data in another table should get as a single row in that situations we can follow like this....


Select * From Customers 


Select * From Hobbies


Select * From CustomerHobbies


Select CustomerID,CustomerName,'Features'=
(Select HobbyDesc+', ' From Hobbies Where HobbyID in 
(Select HobbyID From CustomerHobbies Where CustomerID=Customers.CustomerID)
For XML PATH(''))  From Customers 


Tag: convert, many rows, one row, path, select, single, single row, Sql server, xml

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...