Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2013
    Posts
    30

    Unanswered: SQL statement using two parameters in selecting year and month from budget table

    Hello,
    I need help from an expert SQL professional below is a code for budget it contains the Year and the individual months (GBBGxx). What I want to do is create two parameters to get the year let’s say “2014” and the particular month range for example I want to get budget data from January to March. How can I successfully create a SQL statement to get the two parameters? This is done in db2 via Visual Studio I don’t want to create parameters for all the individual months. I only have reading access to the database. Eventually all of this is going into SSRS. Any tips or links I would really appreciate. Thank you in advance.

    SELECT GBFSYR AS "Year", GBBG01 AS January, GBBG02 AS February, GBBG03 AS March, GBBG04 AS April, GBBG05 AS May, GBBG06 AS June, GBBG07 AS July,
    GBBG08 AS August, GBBG09 AS September, GBBG10 AS October, GBBG11 AS November, GBBG12 AS December,
    GBBG01 + GBBG02 + GBBG03 + GBBG04 + GBBG05 + GBBG06 + GBBG07 + GBBG08 + GBBG09 + GBBG10 + GBBG11 + GBBG12 AS Total
    FROM CAS.GLBUD

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    poor design, but should be able to get what you want, by deleting the months you do not want from the above SQL. I would think you want to filter by year, but you don't have that in there, so... Try something like:

    Code:
    SELECT GBFSYR AS "Year", GBBG01 AS January, GBBG02 AS February, GBBG03 AS March, 
     GBBG01 + GBBG02 + GBBG03 AS Total
     FROM CAS.GLBUD
    Dave

  3. #3
    Join Date
    Mar 2013
    Posts
    30
    Thanks Dave, I will give that a try!

Posting Permissions

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