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.

 All Forums
 SQL Server 2012 Forums
 Analysis Server and Reporting Services (2012)
 Amount between parameters

Author  Topic 

chennaraaj
Starting Member

17 Posts

Posted - 2014-04-01 : 02:46:51
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
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-04-07 : 15:05:51
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
   

- Advertisement -