So thanks to another member here I got my view sorted out :D but now that I've begun to write my stored proc I've ran into another problem!
Basically, my stored proc takes about 30 variables and I want to build a WHERE CLAUSE constraint upon these variables. Only thing is, I would like to check the variable values before adding them to the WHERE clause and if the value of the variable is null or "" then I would like to omit the constraint from the Clause.
Here's a simple example of what I'd like to do:
Select * from TestTable
Where
If (@Variable1 is not null AND @Variable1 <> "")
begin
Column1FromTest Table = @Variable1
end
If (@Variable2 is not null AND @Variable2 <> "")
begin
AND Column2FromTest Table = @Variable2
end
etc....
Is something like this possible? Because I've been looking at Books Online for MSSQL 2k5 and searched the web without any conclusive answers.
Many thanks
Davinski
Basically, my stored proc takes about 30 variables and I want to build a WHERE CLAUSE constraint upon these variables. Only thing is, I would like to check the variable values before adding them to the WHERE clause and if the value of the variable is null or "" then I would like to omit the constraint from the Clause.
Here's a simple example of what I'd like to do:
Select * from TestTable
Where
If (@Variable1 is not null AND @Variable1 <> "")
begin
Column1FromTest Table = @Variable1
end
If (@Variable2 is not null AND @Variable2 <> "")
begin
AND Column2FromTest Table = @Variable2
end
etc....
Is something like this possible? Because I've been looking at Books Online for MSSQL 2k5 and searched the web without any conclusive answers.
Many thanks
Davinski
Comment