Query

  • Hi,

    I have data in table in below format:

    Sexe un homme

    Sexe une femme

    Statut Célibataire

    Statut Marié

    Statut Divorcé/ Séparé / Veuf

    Professio Agriculteur

    Professio Artisan/commerçant/Chef d'entreprise de +10 sal

    and i need the output of my query like below:

    Sexe Statut Professio

    un homme Célibataire Agriculteur

    un femme En concubinage Artisan/commerçant/Chef d'entreprise de +10 sal

    Marié

    Divorcé/ Séparé / Veuf

    Can you please help?

    Thanks

    Puneet

  • can you post the create table statements (DDL) and sample data so we know what we are working on. with out the table structure and sample data we are just guessing.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

  • Sorry if the above was not clear,

    create table test1 (question nvarchar(50),answer nvarchar(200))

    insert into test1 values ('Sexe','un homme')

    insert into test1 values ('Sexe ','une femme')

    insert into test1 values ('Statut ','Célibataire')

    insert into test1 values ('Statut ','Marié')

    insert into test1 values ('Statut ','Divorcé/ Séparé / Veuf')

    insert into test1 values ('Professio ','Agriculteur')

    insert into test1 values ('Professio ','Artisan/commerçant/Chef d''entreprise de +10 sal')

    create table test3 (Sexe nvarchar(100),Statut nvarchar(100),Professio nvarchar(200))

    insert into test3 values('un homme','Célibataire','Agriculteur')

    insert into test3 values('une femme','Marié','Artisan/commerçant/Chef d''entreprise de +10 sal')

    insert into test3 values(Null,'Divorcé/ Séparé / Veuf',Null)

    select * from test1 ---Data in Table

    select * from test3 ---i need the output in this format

  • Excellent job posting ddl and sample data. You need to do a dynamic cross tab. Jeff has a couple articles that explains this.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns[/url]

    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]

    This stuff is pretty complicated because you are going against everything about how databases store and handle data.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 4 posts - 1 through 3 (of 3 total)

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