title: Use a conditional value in a Reporting Services dataset for debugging
body: <p>In the SQL queries for my reporting services datasets, I'd like to be able to use the following pattern:</p>
  
  <pre><code>-- 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 &lt; 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
  </code></pre>
  
  <p>The problem is, Reporting Services ignores the IF statements and "select @now as now" for the report's values, instead of the main query.</p>
  
  <p>Is there a way to accomplish this pattern that gets around this RS limitation?</p>
  
  <p>Update: If you go to the <a href="http://msdn.microsoft.com/en-us/library/ms173839.aspx" rel="nofollow noreferrer">"SET FMTONLY" help page on the MSDN</a>, someone has already noted this problem in a comment at the bottom of the page, and that turning off this option fixes this problem.</p>