Monday, March 19, 2012

Getting result in single query

Hi

I have table like following

Col1 Col2 Col3 Col4 Col5

x y Z T 30

x y Z T 40

A B C D 20

A B C D 30

I want query which will give following kind of result

Col1 Col2 Col3 Col4 Col5

x Y Z T 30,40

A B C D 20.30

I want above result in a single query.

Please help me out

Thanks in Advance

Sanjay Tiwari

You are attempting to retreive data in a demormalized form. SQL doesn't easily do that, but here are a few suggestion that may work for you.

Lists -Field Concatenation
http://groups.google.com/group/microsoft.public.sqlserver.programming/msg/2d85bf366dd9e73e
http://milambda.blogspot.com/2005/07/return-related-values-as-array.html

Lists -Field Concatenation( For SQL 2000 & 2005 )
http://groups.google.com/group/microsoft.public.sqlserver.programming/msg/7e5b4c8a9b9b968a

Lists -Field Concatenation, One Field to Itself for string
SQL 2000
http://omnibuzz-sql.blogspot.com/2006/06/concatenate-values-in-column-in-sql.html
SQL 2005 http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/07/06/871.aspx
http://www.projectdmx.com/tsql/rowconcatenate.aspx

No comments:

Post a Comment