25

I'm using some complicated expressions in Reporting Services to control the value, format etc of data in a report (see MSDN).

Is it possible to insert code comments into these expressions, and if so, what is the syntax?

By code comments I mean something like:

// single line comment
/* or multi line comment */
Sophia
  • 5,643
  • 9
  • 38
  • 43
  • | & IIF(0, "Comment...", "") & | is the best bet work-around for /* insert middle */ string comment. Out of luck for numeric calculations, as IIF() evaluates all parameters. – TamusJRoyce Oct 22 '15 at 16:25

2 Answers2

42

It looks like VB Code.
Try using apostrophe to write a comment.

'This is a sample comment.

This is a guess :)

EDIT: VB doesn't really have multiline comment.
However, try using the following to see if it works


'This is a sample comment _
followed by a new line _
and the comment ends

If that doesn't work, you could do


'This is a sample comment
'followed by a new line
'and the comment ends

EDIT2: Also, it seems that comment should be in the end.

bosskay972
  • 890
  • 1
  • 6
  • 27
shahkalpesh
  • 33,172
  • 3
  • 63
  • 88
  • 1
    Thanks :) I tried it out. That syntax seems to work at the end of an expression only - which makes sense from your link, there's no way to comment mid expression, as its processed as one line. If I use it at the start of an expression, the expression code becomes report output, not good! – Sophia May 20 '09 at 03:59
  • hmm. Does the multiline comment work as expected (using underscore)? – shahkalpesh May 20 '09 at 04:10
  • It isn't actually necessary, as all lines after the first ' are treated as part of the comment. Code highlighting doesn't recognise the extra lines (with or without the underscore) though. – Sophia May 20 '09 at 05:31
  • In SQL Server Reporting Services 2008 R2, Report Builder 3.0 app, this worked for me. I added a comment to the end of the expression, delimiting it with a single-quote mark. – Jim DeLaHunt May 23 '13 at 22:45
  • 1
    Yep. The `'` syntax is great for commenting in SSRS expressions. If you'd like to do some further reading... [MidnightDBA: Commenting SSRS](http://www.midnightdba.com/Jen/2010/07/commenting-ssrs/). The language is Visual Basic and you can read more about it here [MSDocs: Reporting Services Code and Assembly references in Expressions](https://learn.microsoft.com/en-us/sql/reporting-services/report-design/custom-code-and-assembly-references-in-expressions-in-report-designer-ssrs?view=sql-server-2017). – SherlockSpreadsheets Mar 01 '19 at 17:16
2

If you would like to comment a switch statement you could do something like this:

=switch(
   false, "--- First, test if above zero ---"
   , Parameters!Test.Value > 0
   , "Value is above zero. Yeah!"

   , false, "--- Then test if -1 ---"
   , Parameters!Test.Value = -1
   , "I guess the value is unknown"

   , false, "--- Finally catch everything else ---"
   , true
   , "We could not handle this value. Sorry :-\"
)

The lines with false will never be hit and that way you could use them as a comment. Not very beautiful but quite useful :-)

Tech
  • 651
  • 1
  • 8
  • 14