cross apply or other way

  • Hello everybody,

    I have to export the records of a table in a .txt file but in a strange way (in a column). For example I have this table with 3 fields:

    create table prova

    (cod varchar(1),

    des1 varchar(2),

    des2 Varchar (2)

    )

    insert into prova values (1, 'A1', 'A2')

    insert into prova values (2, 'B1', 'B2')

    I need to have the output in this way:

    1 cod 1

    1 des1 A1

    1 des2 A2

    8 S

    1 cod 2

    1 des1 B1

    1 des2 B2

    8 S

    So, I have to put '1' at the begining of every field and '8 S' at the end of every record.

    Anyboody helps me to do this?

    In sql server 2008 and 2012 this functions properly but in sql server 2005 doesn't:

    select d.Val

    from prova

    cross apply values('1 cod ' + Cod),('1 des1 ' + des1),('1 des2 ' + des2),('8 S') d(Val)

  • Answer in the following thread:

    http://qa.sqlservercentral.com/Forums/Topic1574051-3077-1.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply