Monday, March 26, 2012

Multi-Select in Query Possible?

Hi NG,
I want to make a query where I want to let the user select turnovers
within a month, w, day of w aso. and combinated, eg.
give me alle turnovers from month = December and Day of W = Monday
or just all turnovers from w 50
I want to do this within a stored procedure, with the parameters @.year,
@.month, @.w, @.day, @.region. If the value of the parameter is 0, it is
not important.
So an execute could be EXEC sp_GetTurnover 0, 12, 0, 1, 0 for all
Mondays in December
How can I do a Select with this on the Turnover table?
SELECT sum(Amount)
FROM _Turnover
WHERE Year = @.year
AND ...
doesnt work, because it would result Year = 0, thats incorrect.
Thank you very much
Rudiwell, you could go with the following but exec plan probably wouldnt be
efficient:
SELECT sum(Amount)
FROM _Turnover
WHERE
(Year = @.year OR @.year = 0) AND .
(Month = @.month OR @.month = 0)
and so on...
MC
<rudolf.ball@.asfinag.at> wrote in message
news:1133957507.584643.151700@.f14g2000cwb.googlegroups.com...
> Hi NG,
> I want to make a query where I want to let the user select turnovers
> within a month, w, day of w aso. and combinated, eg.
> give me alle turnovers from month = December and Day of W = Monday
> or just all turnovers from w 50
> I want to do this within a stored procedure, with the parameters @.year,
> @.month, @.w, @.day, @.region. If the value of the parameter is 0, it is
> not important.
> So an execute could be EXEC sp_GetTurnover 0, 12, 0, 1, 0 for all
> Mondays in December
> How can I do a Select with this on the Turnover table?
> SELECT sum(Amount)
> FROM _Turnover
> WHERE Year = @.year
> AND ...
> doesnt work, because it would result Year = 0, thats incorrect.
> Thank you very much
> Rudi
>|||Read this article
http://www.sommarskog.se/dyn-search.html
<rudolf.ball@.asfinag.at> wrote in message
news:1133957507.584643.151700@.f14g2000cwb.googlegroups.com...
> Hi NG,
> I want to make a query where I want to let the user select turnovers
> within a month, w, day of w aso. and combinated, eg.
> give me alle turnovers from month = December and Day of W = Monday
> or just all turnovers from w 50
> I want to do this within a stored procedure, with the parameters @.year,
> @.month, @.w, @.day, @.region. If the value of the parameter is 0, it is
> not important.
> So an execute could be EXEC sp_GetTurnover 0, 12, 0, 1, 0 for all
> Mondays in December
> How can I do a Select with this on the Turnover table?
> SELECT sum(Amount)
> FROM _Turnover
> WHERE Year = @.year
> AND ...
> doesnt work, because it would result Year = 0, thats incorrect.
> Thank you very much
> Rudi
>sql

No comments:

Post a Comment