Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Peter7218
Starting Member
2 Posts |
Posted - 2013-04-22 : 09:33:25
|
I am puzzled. What is the purpose of this query?declare @empName varchar(200), @salary moneyset @empName=nullset @salary=1000select *from Employee_Testwhere (@empName is null or Emp_name=@empName)and (@salary is null or Emp_Sal=@salary) |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-04-22 : 09:36:31
|
Purpose is:If you enter any value, then retrieves records which satisfies that conditionOtherwise it will show all records (in the case of @empname = null or @salary = null)--Chandu |
|
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-04-22 : 09:41:44
|
Kinda quiz?? :) Employess without name but salary as 1000CheersMIK |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-22 : 11:55:30
|
quote: Originally posted by MIK_2008 Kinda quiz?? :) Employess without name but salary as 1000CheersMIK
Nopeits just retrieving list of employees who have the passed salary value (1000)the empname = null is to bypass the employeename filter------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Peter7218
Starting Member
2 Posts |
Posted - 2013-04-22 : 19:21:56
|
Any expert out there, PLEASE help to solve my puzzle. |
|
|
logpop
Starting Member
16 Posts |
Posted - 2013-04-22 : 19:44:57
|
It lists all employees with salary 1000. |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-04-22 : 19:50:57
|
As visakh16 explained, the query returns all records where employee salary is 1000. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-04-22 : 21:16:19
|
Just a word of caution: when you use this technique to bypass search conditions in a stored procedure, that can result in some extremely bad execution plans. See Sommarskog's article here for analysis and alternatives: http://www.sommarskog.se/dyn-search-2008.html |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-23 : 12:41:48
|
quote: Originally posted by Peter7218 Any expert out there, PLEASE help to solve my puzzle.
whats the puzzle? isnt my statement answer your puzzle?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|