• Hey guys, This query only serves the purpose to use Pivot without actually using any other column. Suppose you just have some rows returned from anywhere, and you just wish to show all of them (if more than 3, then modify query accordingly by adding more column names) in a columns view. I know it is just a newbie thing, but i thought this was interesting to introduce a new column by adding ROW_NUMBER and use that column in PIVOT instead of using any other column from actual table.

    The query is working fine, just a sort of data was the problem. Below query solves this. I just added 1,2,3 to the data inserted to force the sorting:

    if object_id('comment_text','U') is not null drop table comment_text

    create table comment_text(text nvarchar(1000))

    insert into comment_text values('1FOR DELIVERY ISSUES CONTACT ........ ')

    insert into comment_text values('2AX ENT. ')

    insert into comment_text values('3Person: Ashish')

    select * from comment_text

    SELECT

    TEXT1, isnull(TEXT2,'') as TEXT2,isnull(TEXT3,'') as TEXT3

    FROM

    (SELECT 'TEXT' + convert(nvarchar(1),ROW_NUMBER() over (ORDER BY TEXT)) as ID, TEXT

    FROM COMMENT_TEXT) AS SourceTable

    PIVOT

    (max(TEXT)

    FOR ID IN (TEXT1, TEXT2,TEXT3)

    ) AS PivotTable