PamelaFoxcroft
3/30/2007 4:44:00 PM
Hi
I have a query which looks like this
select * from tablename where col1='test'
Sometimes in my queries I want to do this
select * from tablename where col2='test'
Now I want to wrap this in a stored procedure and I am curious as to
what is the best way to do this, like this:
create proc testproc(@parameter int =0)
as
if @parameter =0
select * from tablename where col1='test'
if @parameter=1
select * from tablename where col2='test'
Is there a more efficient way of doing this? The reason I am asking is
that right now we have two parameters so I will have to do the
following:
create proc testproc(@parameter int =0, @parameter2 int =0)
as
if @parameter =0 and @parameter2=0
select * from tablename where col1='test' and col2='test'
if @parameter=0 and @parameter2=1
select * from tablename where col2='test'
if @parameter=1 and @parameter2=0
select * from tablename where col1='test'
is there a slick way of handling this?