Complicated Query !!

  • Hi folks, this is my first time here... i hope that you can help me with this query

    I have two query and one table

    Queries

    Q1-Training - List of training

    Q2-Group - Groups that must take the training

    Table

    T1 - Training_Group

    Here a query example

    Q1

    Code Name

    -----------------------------------

    AD0041 Advance SQL

    BE0012 Beginner SQL

    NE0001

    ...

    Q2

    Group_Name Group_Code

    -----------------------------------

    Administration ADMIN

    Directors 456

    John Smith 555666

    ...

    T1

    Code Level Group_Code

    -----------------------------------

    AD0041 1 ADMIN

    AD0041 2 456

    AD0041 3 555666

    BE0012 2 456

    Here's my problem :

    I need to make a report that look like that

    Training ADMIN 456 555666

    -------------------------------------

    AD0041 1 1 1

    BE0012 0 1 0

    --> My original text was cut because it was too long.... so it end abruptly ;(

    Thanks for the help !

  • Well - SQL Server 2005 has a PIVOT syntax, which would work just fine for what you're looking at.

    BOL describes it all here:

    http://msdn.microsoft.com/en-us/library/ms177410.aspx?wt.slv=RightRail

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Don't need Q1 ... nothing to join it to Q2 with.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks Matt for the link...

    I'll use the "FOR Training IN ( select * from training ) to get my dynamic columns and do a count on them....

    It was really kind to both of you for your hints !

    Best regards

    David

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

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