Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Analysis Server and Reporting Services (2012)
 Amount between parameters
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

17 Posts

Posted - 04/01/2014 :  02:46:51  Show Profile  Reply with Quote
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 Employee
where Salaries >@Param1 and Salaries < @Param2

Conditions :

1) @Param1 >10000 and @Param2 <25000
2) @Param1 >10000 and @Param2 =''
3) @Param1 <15000 and @Param2 =''
(may or may not pass the values for @Param2)



Flowing Fount of Yak Knowledge

2780 Posts

Posted - 04/07/2014 :  15:05:51  Show Profile  Reply with Quote
I assume one condition is sufficient? Then something like this should do it:
Assuming that in all cases the salary must be greater than @param1 and @param2 is optional. Also assuming that you pass the parameters as varchars, something like this might do it.

select * from Employee
where Salaries > @Param1
  and (coalesce(@Param2, '') <> '' and Salaries < @Param2))
   or (coalesce(@Parame, '') = '')
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000