SQL Server WHERE clause default to all unless variable entered -




i have table of 10 columns of data , i'd able make stored procedure pulls relevant data based on user-defined parameters. simplified version of fact.spend table looks this:

location  |  year  |  spendyear ----------+--------+----------- new york  |  2015  |  25.00 new york  |  2016  |  23.20 dallas    |  2015  |  29.30 dallas    |  2016  |  25.32 san fran  |  2015  |  23.33 san fran  |  2016  |  23.97 

a basic version of i'm trying is:

create procedure sppullspenddata      (@location varchar(20), @spendyear smallint)     select *     fact.spend     location = @location       , spendyear = @spendyear 

but i'd @spendyear parameter optional, defaulting years if there no user input. tried few variations using subqueries, far nothing's worked out quite right.

select     *     fact.spend     (location = @location) ,      (spendyear = @spendyear or @spendyear null) 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -