October 22, 2024 at 7:11 pm
Is the below with nested multi-line comments valid T-SQL code? I thought no because it has nested Multi-line comments but when I drop the code into SQL Server to check its I get no errors.
Below is a section of the script that has the nested comments. The Closing comment marker in the last row is paired up with the opening multi-line comment just to the left of OUTER APPLY. I did try searching on Nested Comments but got no hits related to this but I;ve always thought that nested multi-line comments like below won't work.
) c
/* invoice counts are not currently used */
/* OUTER APPLY (/* Invoices from last 12 post months */
SELECT COUNT(*) NumInv
FROM TRANS
WHERE hperson = tv.hmyperson AND itype = 3
AND upostdate BETWEEN DATEADD(mm,-11,DATEADD(DAY,1,EOMONTH(getdate(),-1)))
AND DATEADD(DAY,1,EOMONTH(getdate(),-1))
) i */
error msgs at lal.
Kindest Regards,
Just say No to Facebook!October 22, 2024 at 7:50 pm
From the T-SQL Documentation: Slash Star (Block Comment) (Transact-SQL)
"Nested comments are supported. If the /* character pattern occurs anywhere within an existing comment, it is treated as the start of a nested comment and, therefore, requires a closing */ comment mark. If the closing comment mark does not exist, an error is generated."
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
October 22, 2024 at 8:45 pm
Thanks Drew. Now the question is, what does SQL consider commented out vs not commented out in my example. In the example I gave will SQL consider everything between teh very first /* and the very last */ as all being commented out?
Kindest Regards,
Just say No to Facebook!October 23, 2024 at 8:40 am
Thanks Drew. Now the question is, what does SQL consider commented out vs not commented out in my example. In the example I gave will SQL consider everything between teh very first /* and the very last */ as all being commented out?
This is very easy to check for yourself. Just paste it into SSMS and see whether it parses
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 23, 2024 at 3:23 pm
From BOL:
Nested comments are supported. If the /* character pattern occurs anywhere within an existing comment, it is treated as the start of a nested comment and, therefore, requires a closing */ comment mark. If the closing comment mark does not exist, an error is generated.
Basically you have to have matching pairs of block comments, otherwise it will throw an error. In the example above, you can type code on the line after /* invoice counts are not currently used */ and it will not be commented out.
Greg
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply