Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

Subtle Line Feed / Carriage Return issue Expand / Collapse
Author
Message
Posted Wednesday, December 22, 2010 9:32 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, May 14, 2013 11:41 AM
Points: 77, Visits: 218
Comments posted to this topic are about the item Subtle Line Feed / Carriage Return issue
Post #1038588
Posted Wednesday, December 22, 2010 9:35 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 11:39 PM
Points: 1,015, Visits: 1,289
I have executed the script - output is 1,2, 3, 4.

Thanks
Post #1038590
Posted Wednesday, December 22, 2010 9:55 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:24 AM
Points: 5,565, Visits: 24,704
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
Post #1038593
Posted Thursday, December 23, 2010 12:08 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 3:34 AM
Points: 3,853, Visits: 4,990
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”
Post #1038623
Posted Thursday, December 23, 2010 12:24 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:51 AM
Points: 1,968, Visits: 369
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
Post #1038626
Posted Thursday, December 23, 2010 12:52 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, July 19, 2013 2:44 AM
Points: 77, Visits: 201
So I lost my point today because I have a fully patched and up to date instance of SQL?
:-(
Post #1038631
Posted Thursday, December 23, 2010 1:22 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:24 AM
Points: 2,451, Visits: 2,342
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)

Post #1038638
Posted Thursday, December 23, 2010 1:49 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 11:39 PM
Points: 1,015, Visits: 1,289
@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
Post #1038642
Posted Thursday, December 23, 2010 2:01 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:24 AM
Points: 2,451, Visits: 2,342
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)

Post #1038644
Posted Thursday, December 23, 2010 2:11 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, September 10, 2012 7:49 AM
Points: 49, 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
Post #1038646
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse