Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Osman TASKIRAN writes "i want to create a stored procedure with dynamic parameters.examplecreate procedure example@param1 int@param2 string@param3 date@param4 floatselect C1,C2,C3,C4,C5 from TestTablewhere C1<>'-'if @param1<>(0 or '' or null =default) then(and C2=@param1)if (@param2<>'') then(and C3=@param2)order by C1gobut this codes doesnt workplease help me."
SELECT C1,C2,C3,C4,C5 FROM TestTable WHERE C1<>'-' AND C2 = CASE WHEN @param1 NOT IN (0,'',null) THEN @param1 ELSE C2 END AND C3 = CASE WHEN C2=@param1 THEN @param2 ELSE C3 ENDORDER BY C1
Brett8-)
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2004-04-26 : 14:07:45
Did you get that to work Brett? I don't think that you can do that in a WHERE.Tara
X002548
Not Just a Number
15586 Posts
Posted - 2004-04-26 : 14:15:43
[code]USE NorthwindGODECLARE @x intSELECT @x = 1000 SELECT * FROM OrdersWHERE OrderId > CASE WHEN @x IS NOT NULL THEN @x ELSE OrderId END[/code]Brett8-)