Hidden Query - Am I missing something?

  • HI There
    I am trying to recreate some existing reports and have access to the rdl files.

    When I open the query behind the dataset I see below, but I am unsure how this gets populated, any ideas? I am assuming the real query is in a variable somewhere, but the @query Parameter is also empty.

    if @Query is not null
    exec (@Query)
    else
    begin
    if exists(select 1 where object_id('tempdb..#report') is not null) drop table #report
    create table #report(
    [Column1] varchar(35) NULL ,
    [Column2] varchar(35) NULL ,
    [Metric1] money null)

    select r.[Column1] AS Group1, r.[Column2] AS Group2, r.[Metric1] AS Group3
    from #report r

    End

  • Oh fun!
    This sounds like it's the end part of some dynamic SQL statement, so you need to track down exactly what query is being built, so you know the data it returns.
    if @Query is not null
    exec (@Query)

    All the tables that start with # are temporary tables. You need to find what object (stored procedure, most likely) created them. In a nutshell, they're probably breaking a hideous query up by inserting intermediate results into temporary tables and then basing their reports on those. But without the definition of those tables, it's hard to say exactly how to answer your question.

    See if you can find the procedures that create those tables (and maybe populate them). Then the procedure will make more sense.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply