question

GPO avatar image
GPO asked

Reporting service tsql syntax - commenting

Hi All In a recent post I indicated that I've just moved into a new job (reporting) in a new organization and I've noticed some oddness that may or may not be significant. In the SQL that goes into the rdl files here, I've noticed that there is almost NEVER any commenting in the code. Furthermore, there is often a complete absence of easy-on-the-eye formatting, with everything jammed up against the left margin. Am I missing something here? These people have years of experience with SSRS whereas I have less than 12 months and so I'm wondering whether there are any gotchas that mean you should not comment the code in RDLs the way you would in a *.sql file. Regards GPO
t-sqlssrsreporting-servicescomments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
I've put comments into SSRS queries before without any problems. And formatting does get retained. I suspect that the more complex queries are developed outside of SSRS before being copied in, or built up using the query designer, which may not be so well-behaved.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

GPO avatar image
GPO answered
@ThomasRushton I have discovered a gotcha (in SSRS2000 at least). If you put something in a comment that can be interpreted as a parameter it looks like you'll throw an error message. I had: -- ? some comment in an rdl and got the following message > "An error occurred while executing the > query. Incorrect syntax near '?'..." Same thing occurs with /*? some comment */
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

As an addendum to this (rather old) post, it is also worth noting that if you are pasting really long SQL into the textbox in SSRS that holds the code, it silently truncates after a certain number of characters. If this generates an error when you run the report, great, at least you know you have a problem. If, however, you're unlucky enough that the code is truncated somewhere that doesn't generate an error (say just before a UNION ALL, like happened with me) then you could have an invisible problem, with your report happily spitting out the wrong answer, and not tellign you it's wrong. Yet another good reason to use stored procedures.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.