SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Basic CASE Statement in Cascading parameterized report


Basic CASE Statement in Cascading parameterized report

Author
Message
Mac1986
Mac1986
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 791
Hi All,
Writing a small CASE statement that in SQL Server. Below is what I'm try to accomplish.

If the user selects 'MAC' as the input parameter in the report, SSRS should use below query.
BEGIN
SELECT NetworkName, SampleTime, [Max] FROM vinny..PerfData_CPUServerView (nolock)
Where NetworkName in (@ServerName)
And SampleTime >= @StartDateTime and SampleTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101)
Order by SampleTime asc
END


Else it should this query.
BEGIN
select NetowrkName.SnapshotTime, ProcessUsePct from vinny..SqlResourceUseHistoricView (NOLOCK)
Where B.NetworkName in (@ServerName)
And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101)
Order by SnapshotTime asc
END


I tried IF ELSE statement but SSRS is not giving results for cascading parameterized reports.
Please help...
Mac1986
Mac1986
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 791
Below is what I came up with. Please help me get the right one. I'm getting NULL when i run it.

DECLARE @ApplicationName Varchar(50) = 'Informatica'
DECLARE @EnvironmentName Varchar(50) = 'UAT'
DECLARE @ServerName Varchar(50) = 'TK5BIINFMAPPE02'
DECLARE @StartDateTime DateTime = '2013-03-12 00:00:00.000'
DECLARE @EndDateTime Datetime = '2013-03-29 00:00:00.000'
DECLARE @Statement varchar(max)
Select @Statement = ('select NetworkName,SnapshotTime, ProcessUsePct from ')

SELECT @Statement = @Statement +
CASE
when @ApplicationName = 'Informatica' Then ' vinny..PerfData_CPUServerView (NOLOCK) Where B.NetworkName in (@ServerName) And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101) Order by SnapshotTime asc'
when @ApplicationName = 'Velocity' Then ' vinny..SqlResourceUseHistoricView (NOLOCK) Where B.NetworkName in (@ServerName) And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101) Order by SnapshotTime asc'
when @ApplicationName = 'MSCloud' Then ' vinny..SqlResourceUseHistoricView (NOLOCK) Where B.NetworkName in (@ServerName) And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101) Order by SnapshotTime asc'
when @ApplicationName = 'OA' Then ' vinny..SqlResourceUseHistoricView (NOLOCK) Where B.NetworkName in (@ServerName) And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101) Order by SnapshotTime asc'
end

Exec @Statement

Select @Statement


Mac1986
Mac1986
Mr or Mrs. 500
Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)Mr or Mrs. 500 (561 reputation)

Group: General Forum Members
Points: 561 Visits: 791
Basically what I'm trying to achieve is, Based on selected parameter of the report, Query used should change.
I have only 2 Queries.

Query1 should be used when @ApplciaitonName 'Informatica' is selected

and Queriy2 should be used for rest of all @ApplicationNames

Please do help.
Steven.Howes
Steven.Howes
SSC Eights!
SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)

Group: General Forum Members
Points: 874 Visits: 2346
so
IF @ApplicationName = 'MAC'
BEGIN
SELECT NetworkName, SampleTime, [Max] FROM vinny..PerfData_CPUServerView (nolock)
Where NetworkName in (@ServerName)
And SampleTime >= @StartDateTime and SampleTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101)
Order by SampleTime asc
END
ELSE
BEGIN
select NetowrkName.SnapshotTime, ProcessUsePct from vinny..SqlResourceUseHistoricView (NOLOCK)
Where B.NetworkName in (@ServerName)
And Snapshottime >= @StartDateTime and SnapshotTime <= CONVERT(date, DATEADD(dd, 1, @EndDateTime), 101)
Order by SnapshotTime asc
END

Didn't work for you?
Steven.Howes
Steven.Howes
SSC Eights!
SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)SSC Eights! (874 reputation)

Group: General Forum Members
Points: 874 Visits: 2346
Never mind I just saw your other post...

http://www.sqlservercentral.com/Forums/Topic1438173-150-1.aspx
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search