-2

I want to merge three record into one one.

My query is like this : select Value from table where ID '1'

For now I have the following result :

A
B
C

Is it possible to have the result like

Value1|Value2|Value3

A     | B    | C

Thanks in advance.

Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48
MoThA
  • 11
  • 1
  • Possible duplicate of [Convert Rows to columns using 'Pivot' in SQL Server](http://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server) – Ullas Feb 28 '17 at 09:37

1 Answers1

0

You can check this.

    DECLARE @s VARCHAR(max);
    DECLARE @a VARCHAR(max);
    select 
    @a = 
    stuff((
    select ''',[Value'+ 
            CAST(row_number() over(order by u.username) AS nvarchar(20))+
            ']=''' +
             u.username
    from users u
    for xml path('') 
    ),1,2,'') ;

    set @s = 'select '+@a + ''''
    exec(@s)
Levent Saatci
  • 404
  • 3
  • 4