Unanswered: SQL statement using two parameters in selecting year and month from budget table
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
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:
SELECT GBFSYR AS "Year", GBBG01 AS January, GBBG02 AS February, GBBG03 AS March,
GBBG01 + GBBG02 + GBBG03 AS Total