CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Pivot Table and ORDER BY -problem

    Hello

    I use MS SQL 2000. I need to present some rows as new columns.
    Thanks to help hspc I know how to do it but ...

    I think that my query ( please find enclosed file ) is simply wrong.
    To get result without error I need to add one extra column R.ReelGrade. Without this column I returned an error:
    Column R.ReelGrade is invalid in the selected list because it is not contained in either an aggregatefunction or the GROUP BY clasue

    I don't need to ORDER BY the second column. My oryginal query will SELECT at least 20 columns, I don't want to add 20 extra column to ORDER BY calsue.
    Could you please tell me what my query should be.

    PS
    I found some info about it hereSQL GROUP BY techniques but it is not clear enough for me.

    Thanks in advance
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Pivot Table and ORDER BY -problem

    If you download the SQL Server Mgmt Studio, and SQLExpress, you can use the wizard to design your query, and run it.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Pivot Table and ORDER BY -problem

    Basically, when you use a Group By, then you can't select any information from the query which isn't in the Group By clause or in an aggregated function.

    The reason for this is that when you run "Group By" you combine multiple rows into one row. And if the column then isn't "Grouped" or aggregated, it means multiple values of the same column would be in the row, and that can't be selected.

    I'm not sure what is wrong with your query though, as I've not looked too much, but if you want to select ReelGrade out without having it aggregated or in the group by clause, the only method you have is to either make it a sub query, or select the result into a temporary table, and use that as foundation to join into the information about ReelGrade.

    Hope this helps.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Pivot Table and ORDER BY -problem

    Are your tables called this?

    Code:
    ReelGradeData
    ReelGradeDetail
    as you have in your labels?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 1999
    Location
    Poland
    Posts
    278

    Re: Pivot Table and ORDER BY -problem

    Quote Originally Posted by dglienna
    Are your tables called this?

    Code:
    ReelGradeData
    ReelGradeDetail
    as you have in your labels?

    yes, my tables name are:

    Table1 Name / "ReelGradeData"
    Table2 Name / "ReelGradeDetail"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured