In the SQL queries for my reporting services datasets, I'd like to be able to use the following pattern:
-- Used to enable/disable diagnostic statements
declare @DEBUG bit
set @DEBUG = 0
-- Get current date/time.
declare @now datetime; set @now = getdate()
if @DEBUG = 1 select @now as now
-- Create a table to contain the chart values for the last 30 days.
declare @reportValues table
(
reportDate datetime,
x int
)
-- Populate the table with the last 30 days.
declare @counter int; set @counter = 0
while @counter < 5
begin
insert into @reportValues select dateadd( day, -@counter, @now ), @counter
set @counter = @counter + 1
end
if @DEBUG = 1 select * from @reportValues
select sum(x) as total from @reportValues
The problem is, Reporting Services ignores the IF statements and "select @now as now" for the report's values, instead of the main query.
Is there a way to accomplish this pattern that gets around this RS limitation?
Update: If you go to the "SET FMTONLY" help page on the MSDN, someone has already noted this problem in a comment at the bottom of the page, and that turning off this option fixes this problem.