• 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