Append multiple vertical rows into single Horizontal row.

Dear Experts,

                        I want to append vertical row result into horizontal

CREATE  TABLE  #mable(mid INT, token nvarchar(16))

INSERT INTO #mable VALUES (0, 'foo')
INSERT INTO #mable VALUES(0, 'goo')
INSERT INTO #mable VALUES(0, 'joo')
INSERT INTO #mable VALUES(0, 'poo')
INSERT INTO #mable VALUES(1, 'hoo')
INSERT INTO #mable VALUES(1, 'moo')

Desired output

MID TOKEN MID2 TOKEN2 MID3 TOKEN3 MID4 TOKEN4
0 foo 0 goo 0 Joo 0 Poo
1 hoo 1 moo NULL NULL NULL NULL

Please help

May 20th, 2015 4:59am

We are not here to do your work.  This is effectively the same question as a previous one.

append vertical result into horizontal

You should take some time to learn and understand the queries discussed in the previous one.  Perhaps your biggest hurdle is understanding that presentation of data is very different from querying the data.  TSQL is not intended to handle the presentation and there are tools to pivot data and arrange data in "pretty" ways.  In addition, you have also fallen into the trap of using a very small subset of data as an example, as well as the trap of using utterly nonsense DDL and sample data.  When your schema and data do not have any useful or obvious purpose, you limit the ability of others to both interpret your database and to interpret your goal. 

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2015 8:49am

OK thank you.
May 21st, 2015 12:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics