Thursday, 15 August 2013

sql server - How to write where clause for quantitative column or date column parameters in stored procedure? -



sql server - How to write where clause for quantitative column or date column parameters in stored procedure? -

here question: need create table stored procedure, , have many quantitative columns or date columns,

weight decimal null cost money null wattage int null

and when use

create procedure table.p @weight decimal @cost money @wattage int select weight, cost, wattage table weight= or @weight null , cost=

i don't know how write clause, know should utilize between function how write quantitative or date columns?

thanks!

if utilize between you'll need upper , lower values of course. take you've shown in question , filter on equality passed values (and ignore weren't passed or passed null), seek this:

select weight, cost, wattage table (@weight null or weight = @weight) , (@cost null or cost = @cost) , (@wattage null or wattage = @wattage)

a between query have few more conditions, general concept of (parameter null or condition-using-not-null-parameter) still holds.

sql-server stored-procedures

No comments:

Post a Comment