Wierd month problem

  • Hello All,

    Have a need where I pass in the start month and end month as an ints to a stored proc. The data has hard coded fields for months. For example, column names are 'month1', 'month2', 'month3' ... up to 'month12'.

    Now 'month1' is suppose to be October, 'month2' is suppose to be November, etc.

    when i pass in the start month and end month values of ints to the proc, i am suppose to select start month to end month columns in the select statement. What is the best way to do this?

    Thanks for your time.

  • To get a tested answer, please post your tale definition, some sample data and required results. To do this in a readily consumable manner pleas click on the first link in my signature lock and read the article, which by the way includes T-SQL statements to allow you to provide the information easily

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Query the data vertically, returning months as rows, and have the presentation layer pivot it. Excel, SSRS, CrystalReports, et al, can pivot rows into columns efficiently and well.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • ramadesai108 (10/7/2011)


    Hello All,

    Have a need where I pass in the start month and end month as an ints to a stored proc. The data has hard coded fields for months. For example, column names are 'month1', 'month2', 'month3' ... up to 'month12'.

    Now 'month1' is suppose to be October, 'month2' is suppose to be November, etc.

    when i pass in the start month and end month values of ints to the proc, i am suppose to select start month to end month columns in the select statement. [font="Arial Black"]What is the best way to do this?[/font]

    Thanks for your time.

    For the way you have it laid out, Dynamic SQL to build the correct SQL Statement.

    --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)

  • I agree with GSquared.

    I had a similar problems lining up the appropriate lengths and pressures of a mathematical problem along with offset calender months.

    Using the transpose tool on the origin data made it easier to work with.

    Can you feedback on how you got on with this?

    I've got another project coming up for an SQL database to sort and verify the amp output of a batch counter against a current input for an ampere hour meter It's not even something i fully understand...

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

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