SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Subtle Line Feed / Carriage Return issue


Subtle Line Feed / Carriage Return issue

Author
Message
dbuendiab
dbuendiab
SSC Veteran
SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)SSC Veteran (259 reputation)

Group: General Forum Members
Points: 259 Visits: 218
Comments posted to this topic are about the item Subtle Line Feed / Carriage Return issue
Hardy21
Hardy21
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2782 Visits: 1399
I have executed the script - output is 1,2, 3, 4.

Thanks
bitbucket-25253
bitbucket-25253
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16175 Visits: 25280
After being told that I had selected the wrong answer, I copied the code to SSMS for SQL 2005, and to SSMS SQL 2008 ....

In BOTH 2005 and 2008 I DID NOT get what was deemed to be the correct answer.

Further the support for the so called correct answer is a sole forum posting to which NO ONE respond to .....AUGHHHHHHHHHH

Now I will not say what the correct answer is, but for sure it is not what the question says it is.

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17478 Visits: 7423
Having investigated this further, I have found that the "correct" answer occurs on SQL2000 and SQL2005 RTM.
this was registered as a bug and repaired with CU2 of SQL2005 (also included in service pack 1).

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
ziangij
ziangij
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3616 Visits: 377
Hardy21 (12/22/2010)
I have executed the script - output is 1,2, 3, 4.


even i got the same answer... lost my point today Sad
AJN
AJN
SSC-Enthusiastic
SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)SSC-Enthusiastic (103 reputation)

Group: General Forum Members
Points: 103 Visits: 201
So I lost my point today because I have a fully patched and up to date instance of SQL?
:-(
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7616 Visits: 3401
It's not a bug: CR is carriage return, so the line is the same.
The line 2 is not printed beacuse the print command is joined to the commented line.
So, change the single line comment with /**/. All lines will be printed.

declare @sql varchar(100)
declare @cr char(1)
declare @nl char(1)
set @cr = char(13)
set @nl = char(10)
set @sql =
'print 1' + @cr + @nl +
'/* Comment one */' + @cr +
'print 2' + @cr + @nl +
'/* Comment two*/' + @cr + @nl +
'print 3' + @cr + @nl +
'/* Comment three*/' + @nl +
'print 4'

print '
What you see...'
print '-----------------------'
print @sql
print '
is not what you get!'
print '-----------------------'
exec (@sql)



I run on tuttopodismo
Hardy21
Hardy21
SSCrazy
SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)SSCrazy (2.8K reputation)

Group: General Forum Members
Points: 2782 Visits: 1399
@carlo: you are right.
But as per the question, we should give answer for the question: What will you get executing this T-SQL code in Query Analizer (SQL2K) or Management Studio (2005)?

So, EXEC(@sql) result is 1,2,3,4.

Thanks
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7616 Visits: 3401
Hardy21 (12/23/2010)
@carlo: you are right.
But as per the question, we should give answer for the question: What will you get executing this T-SQL code in Query Analizer (SQL2K) or Management Studio (2005)?

So, EXEC(@sql) result is 1,2,3,4.

If you get 1,2,3,4
that means that in the script you do not report single line comments.
The script in @sql looks like this:
PRINT 2 is joined to the upper line.

set @sql = 
'print 1
-- Comment one print 2
-- Comment two
print 3
-- Comment three
print 4
'
exec (@sql)



I run on tuttopodismo
Bobby VK
Bobby VK
Valued Member
Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)Valued Member (69 reputation)

Group: General Forum Members
Points: 69 Visits: 10
What is it with questions being wrong on this site?

SQL 2008 Developer Edition. I copied your code, pasted into my SSMS and this is the exact output:

What you see...
-----------------------
print 1
-- Comment one
print 2
-- Comment two
print 3
-- Comment three
print 4
is not what you get!
-----------------------
1
2
3
4
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search