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 |
chennaraaj
Starting Member
17 Posts |
Posted - 2014-04-07 : 04:41:17
|
Hi All,I am having table Employee with Employee Salaries details,from that i need to get the values based on parameters(@Param1,@Param2)select * from Employeewhere Salaries >@Param1 and Salaries < @Param2Conditions : 1) @Param1 >10000 and @Param2 <250002) @Param1 >10000 and @Param2 =''3) @Param1 <15000 and @Param2 =''(may or may not pass the values for @Param2)rk |
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-04-07 : 05:04:05
|
Are you looking for this......DECLARE @param1 INT = 10000DECLARE @Param2 INT = 25000DECLARE @Param3 INT = NULLDECLARE @Param4 INT = 15000SELECT * FROM Employee WHERE Salary BETWEEN @param1 AND @Param2SELECT * FROM Employee WHERE Salary > @param1 AND @Param3 IS NULLSELECT * FROM Employee WHERE Salary < @Param4 AND @Param3 IS NULL---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2014-04-07 : 21:58:07
|
How can you tell whether to use 2 or 3 if you leave out param2? I think what you are after isselect * from Employeewhere Salaries >@Param1 and (Salaries < @Param2 OR @Param2 is null) |
|
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-04-08 : 00:36:30
|
quote: Originally posted by LoztInSpace How can you tell whether to use 2 or 3 if you leave out param2? I think what you are after isselect * from Employeewhere Salaries >@Param1 and (Salaries < @Param2 OR @Param2 is null)
Sorry to say you missed the third condition Which is not possible to write in a single query........LoztInSpace---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
|
|
|