I have a table say
tbl
col1 col2
1 A
2 B
3 C
Null F
5 G
Null H
Here is what I want a parameter is passed to my stored proc
@col1 int = Null
I want to select a value from tbl1 according to @col1
if @col1 is null I will select all the records of tbl
otherwise I will select records wil @col1 = @col1
I wrote it like this
select * from tbl
where (col1 = isnull(@col1, col1) or ((@col1 is null) and (col1 is null)))
it is giving me the right answer but performance wise I am not satisfied
Is there other way to do that considering performance/
Thanks
tbl
col1 col2
1 A
2 B
3 C
Null F
5 G
Null H
Here is what I want a parameter is passed to my stored proc
@col1 int = Null
I want to select a value from tbl1 according to @col1
if @col1 is null I will select all the records of tbl
otherwise I will select records wil @col1 = @col1
I wrote it like this
select * from tbl
where (col1 = isnull(@col1, col1) or ((@col1 is null) and (col1 is null)))
it is giving me the right answer but performance wise I am not satisfied
Is there other way to do that considering performance/
Thanks