How to merge the several records into one

How to merge the several records into one

Post by Hongb » Fri, 08 Feb 2002 05:26:11



Hi there,

I have a table like this:

dealercode    representive
A1023            Brian
A1023            John
A1023            Mary
B1105            Tim
B1104            Brian
B1104            Andrew

I would like to merge some records  to get like this
dealercode    rep1            rep2        rep3        rep4 ....
A1023           Brian          John        Mary
B1105            Tim
B1104            Brian         Andrew

Could you help me how can write sql script?

Hongbo

 
 
 

How to merge the several records into one

Post by BP Margoli » Fri, 08 Feb 2002 11:37:00


Hongbo,

If you know in advance the number of columns in the result set, try:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175574.

If you have a variable number of columns, try:
http://www.sqlmag.com/Articles/Index.cfm?ArticleID=15608

-------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.


Quote:> Hi there,

> I have a table like this:

> dealercode    representive
> A1023            Brian
> A1023            John
> A1023            Mary
> B1105            Tim
> B1104            Brian
> B1104            Andrew

> I would like to merge some records  to get like this
> dealercode    rep1            rep2        rep3        rep4 ....
> A1023           Brian          John        Mary
> B1105            Tim
> B1104            Brian         Andrew

> Could you help me how can write sql script?

> Hongbo