4
I have a proc that gets a product ID. If it gets NULL, then it should list all products. If it gets the specific ID, it should list only that product.
There is some way to do this without having to create a dynamic query?
4
I have a proc that gets a product ID. If it gets NULL, then it should list all products. If it gets the specific ID, it should list only that product.
There is some way to do this without having to create a dynamic query?
5
Tries:
SELECT * FROM tabela WHERE (id = @varid OR @varid IS NULL)
Of course! That’s right.
1
Just to complement the solution of the friend there:
You can also use the function isnull
SELECT * FROM tabela WHERE id = isnull(@varid, id)
Browser other questions tagged sql-server tsql stored-procedures
You are not signed in. Login or sign up in order to post.
Can you change the proc? It would be easier if you post her body.
– Marcos Regis