K
Karen Middleton
Hello All
I have a table - CustSales with the following structure:
Customer
Qty
Amount
Calmonth
and I have data in this table for the following
calmonth's = 0012004
0022004
0032004
0042004
0052004
0062004
0072004
0082004
0092004
0102004
0112004
Now from this table I have a need to do reporting for current month
and the current month can be anything like 0012004 or 0022004 or
0032004 or 0112004
that works fine with the following query:
select customer, qty, amount from CustSales where calmonth = [calm];
so when I run this query I enter a value for the parameter - calm and
it reports the current month values for that calmonth parameter
entered.
Now from this same table I want to do YTD (year to date ) reporting as
well
like the following:
select customer, sum(qty), sum(amount) from CustSales
where ( ( calmonth >= 2004001 ) and ( calmonth <= [calm] ) );
But my problem is I cannot use this hardcoding like ( calmonth >=
2004001 )
since the same table as data for year 2002 , 2003, 2004 so if the user
entered the parameter value as 2003005 I want the value to be
automatically computed for 2003001 as the from period.
Please advice how I can compute this from period automatically in the
query given the toperiod parameter value like 2003005 I want the from
period computed automatically as 2003001.
Any ideas how to do this is highly appreciated.
Thanks
Karen
I have a table - CustSales with the following structure:
Customer
Qty
Amount
Calmonth
and I have data in this table for the following
calmonth's = 0012004
0022004
0032004
0042004
0052004
0062004
0072004
0082004
0092004
0102004
0112004
Now from this table I have a need to do reporting for current month
and the current month can be anything like 0012004 or 0022004 or
0032004 or 0112004
that works fine with the following query:
select customer, qty, amount from CustSales where calmonth = [calm];
so when I run this query I enter a value for the parameter - calm and
it reports the current month values for that calmonth parameter
entered.
Now from this same table I want to do YTD (year to date ) reporting as
well
like the following:
select customer, sum(qty), sum(amount) from CustSales
where ( ( calmonth >= 2004001 ) and ( calmonth <= [calm] ) );
But my problem is I cannot use this hardcoding like ( calmonth >=
2004001 )
since the same table as data for year 2002 , 2003, 2004 so if the user
entered the parameter value as 2003005 I want the value to be
automatically computed for 2003001 as the from period.
Please advice how I can compute this from period automatically in the
query given the toperiod parameter value like 2003005 I want the from
period computed automatically as 2003001.
Any ideas how to do this is highly appreciated.
Thanks
Karen