May 26, 2009 at 12:48 pm
I am not sure if i have to use CASE or IF but here is the requirement.
I have a ssrs report where it has 3 drop down list for
1.DBname
2.Year
3.Month
How do i populate report with switch cases where it should also accept nulls if nothing is selected from the drop down list.
May 27, 2009 at 7:15 pm
I think my question was is not clear, let me explain it.
I have 3 parameters for my store proc and i would like an IF or CASE statements to select these parameters in all possible probabilities, like
1. if @month='' and @year='' and @dbname='' , it has to select all records
2. if @month='' and @year'' and @dbname=''.then select * .....where year=@year
3. if @month'' and @year='' and @dbname='' then select * ..where month=@month and dbname=@dbname
4. and so on.....
it has to satisfy all possible probabilities.
Is there any easy way to do so....
May 27, 2009 at 11:30 pm
allow null value from the report parameter and add logic in the SP or TSQL like ......... WHERE (@DBNAME IS NULL OR DBNAME = @DBNAME)
this way if you passed the null value from the report parameter it will return all the record or if any DBNAME is passed then it will pull the databased on filter condition.
May 28, 2009 at 4:09 am
Hi,
Try this, please remember to cast your parameter.
select * from tablename
where monthColumnName = case when @month='' then monthColumnName else @month end
AND
yearColumnName = case when @year='' then yearColumnName else @year end
AND
dbname = case when @dbname='' then dbname else @dbname end
May 28, 2009 at 7:04 am
Tara (5/27/2009)
I think my question was is not clear, let me explain it.I have 3 parameters for my store proc and i would like an IF or CASE statements to select these parameters in all possible probabilities, like
1. if @month='' and @year='' and @dbname='' , it has to select all records
2. if @month='' and @year'' and @dbname=''.then select * .....where year=@year
3. if @month'' and @year='' and @dbname='' then select * ..where month=@month and dbname=@dbname
4. and so on.....
it has to satisfy all possible probabilities.
Is there any easy way to do so....
suggestion:
select @month = nullif(@month,''), @year = nullif(@year,''), @dbname = nullif( @dbname,'')
...
select ...
from ...
where month = isnull(@month,month)
and year = isnull( @year, year )
and dbname = isnull( @dbname, dbname )
May 28, 2009 at 7:27 am
yes i did get the result i need but i would like to add 1 more functionality to it.
how would i compare from one parameter to other like say..
compare between server1 and server2/ dbname1 and dbname2 if they are matching.
June 3, 2009 at 3:19 pm
We use this to make sure we are in DEV
before we call a stored procedure that deletes data
use master
go
declare @DEV_sysserver_srvname varchar (20)
select @DEV_sysserver_srvname = (select srvname from sysservers
where srvname = 'yourservername')
select @DEV_sysserver_srvname
IF (select srvname from sysservers where srvname = 'yourservername') = @dev_sysserver_srvname
Use yourDB
GO
Print 'using yourDB'
Exec someproc
Print 'Life is good'
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply