SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

chennaraaj
Starting Member

India
16 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)

regards,
RK


rk

gbritton
Constraint Violating Yak Guru

416 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  
 New 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.09 seconds. Powered By: Snitz Forums 2000