|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 11:41 AM
Points: 77,
Visits: 218
|
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877,
Visits: 1,159
|
|
I have executed the script - output is 1,2, 3, 4.
Thanks
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 5:40 PM
Points: 5,123,
Visits: 20,370
|
|
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
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 8:26 AM
Points: 3,164,
Visits: 4,344
|
|
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”
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:53 AM
Points: 1,552,
Visits: 359
|
|
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
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, June 10, 2013 2:37 AM
Points: 71,
Visits: 195
|
|
So I lost my point today because I have a fully patched and up to date instance of SQL? :-(
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 1:10 AM
Points: 1,998,
Visits: 1,866
|
|
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)
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877,
Visits: 1,159
|
|
@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
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 1:10 AM
Points: 1,998,
Visits: 1,866
|
|
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)
|
|
|
|
|
SSC 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
|
|
|
|