Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:49:14+00:00 2026-05-26T16:49:14+00:00

this is (maybe) an already asked question… but i’ve some difficul to solve my

  • 0

this is (maybe) an already asked question… but i’ve some difficul to solve my problem.
I need to transpose to column a row-based query.
I explain:
This is my actual query result

Year     Month     Value
2010      Jan         19
2010      Feb         10
...

I need

Year      Jan        Feb         ...         Dec
2010      19         20          ...         ...
2011      11         ..          ...           

Actually, my main query is very simple..

SELECT     SUM(QTYCALC) AS TOT, YEAR(SCHEDSTART) AS MyYear, MONTH(SCHEDSTART) AS MyMonth
FROM         PRODTABLE
GROUP BY YEAR(SCHEDSTART), MONTH(SCHEDSTART)

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:49:14+00:00Added an answer on May 26, 2026 at 4:49 pm

    You need to use PIVOT to achieve that – for explanation and some examples see http://msdn.microsoft.com/en-us/library/ms177410.aspx and http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx

    Another option would be:

    SELECT
    YEAR(SCHEDSTART) AS MyYear, 
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 1 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Jan,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 2 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Feb,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 3 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Mar,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 4 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Apr,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 5 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS May,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 6 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Jun,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 7 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Jul,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 8 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Aug,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 9 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Sep,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 10 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Oct,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 11 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Nov,
    (SELECT SUM(X.QTYCALC) FROM PRODTABLE X WHERE MONTH(X.SCHEDSTART) = 12 AND YEAR(X.SCHEDSTART) = YEAR(P.SCHEDSTART)) AS Dec
    FROM       PRODTABLE P
    GROUP BY YEAR(P.SCHEDSTART)
    

    You should check both (PIVOT and this) regarding performance/execution plan…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has already been asked but I am in urgent need
This is a question maybe already asked. My query is SELECT Year, Month, Line,
I already asked a similar question but this one is a bit different/specific: I'm
I have already asked this question in offical Flot google groups, but got no
Dear all, the question like this one has been already asked , but among
This maybe a stupid question, but as I can not easily undo my change
I know this maybe a very basic question but I'm having a bit of
I know this maybe a basic question but I just can't seem to find
Ok so this maybe a simple/silly question but I don't know so here goes:
This question maybe a better fit on The Business of Software forum but despite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.