August 2, 2010 at 12:46 pm
declare @myParam int
set @myParam = 6 (or null)
select *
from entry
where
(entry.uid = @myParam OR @myParam is null)
No need to make the param zero. This worked as expected so that
when myparam = 6 it returned the single row
when myparam = null it returned all
when myparam = 666666666 it returned none. (an int not in the column)
On the face of it it looks more performant then the coalesce method. If I try some tests I will post the results.
Dave
Trainmark.com IT Training B2B Marketplace
(Jobs for IT Instructors)
February 7, 2011 at 4:24 am
Based on my experience, the one using Dynamic SQL is the best solution. using or operator is not recommended,
1.cause it will SQL Server to misuse index.
2.When the traffic is high, it consume more CPU resource....
Viewing 2 posts - 106 through 106 (of 106 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy