|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
Trick question but confused with explanation & query posted in the answer because it throws an error. Thanks Hugo for explanation. I learn usage of delimiters.
Thanks
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:04 AM
Points: 1,968,
Visits: 1,819
|
|
Obvious! In the daily work you do not need a special syntax. But, sometime my clients ask me for something special. And thanks to the delimiter I can extract data and send them without writing an application outside sqlserver. In the example, unfortunately, most of syntax has been lost because of html tag. So, I provide another simplest one. The following script build syntax to expand sp, functions or views, comment or uncomment the type of object and substitute %my_proc% with the name of object, run it and than select all the result copy and paste and execute in the query window.
set nocount on select 'exec sp_helptext ' AS [--],o.name from sysobjects o(readuncommitted) where o.xtype IN('' ,'P '--: stored procedure' --,'IF'--: inline function' --,'FN'--: scalar function' --,'TF'--: table function' --,'V '--: view' --,'TR'--: trigger' ) and o.name like '%my_proc%' and o.name not like 'dt[_]%' order by o.Name set nocount off
At last, the 84% of users learned 3 new things: 1) Read carefully the Qotd. 2) Use of delimiter. 3) Only lack of fantasy is the limit.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Yesterday @ 1:32 AM
Points: 3,187,
Visits: 4,140
|
|
Carlo Romagnano (10/13/2010) In the example, unfortunately, most of syntax has been lost because of html tag. Could you please zip that script and attach it to your next message?
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 2:53 AM
Points: 1,526,
Visits: 359
|
|
thanks Hugo... 
Hugo Kornelis (10/12/2010) I got two points for answering a question that tests no useful skill whatsoever? Come on, Steve! Even one point would have been more than enough for this one!
Carlo, thanks for the effort of submitting a QotD (not cynical!). But next time, please submit a question about something that actually has any real use for SQL Server professionals. I can imagine someone accidentally not matching opening and closing brackets (especially if []] is used somewhere in the bracketed text). But then also having an extraneous closing bracket in another batch, that is sent at the same time, and with code after that bracket that "just happens" to make the original code complete so that no error is thrown? The chance of that happening anytime, anywhere, is infenitely small. So noone will learn anything useful from this question. Since you obviously (based on the explanation) wanted to educate visitors of this site about the usefulness of using brackets to delimit identifiers, you should have submitted a question that did just that, instead of deliberately adding nonsensical code to ensure as little people as possible get it right. The aim of this site should not be to get as many people as possible to fail, but to show as many people as possible the great stuff SQL Server can do.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, October 14, 2010 11:18 PM
Points: 1,
Visits: 5
|
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:46 PM
Points: 18,732,
Visits: 12,329
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 9:38 AM
Points: 236,
Visits: 244
|
|
| Management studio shows me this script mostly in black meaning there is something wrong in the script even if it's completed successfully. I guess even colorblind people can see it. I don't see the point of this question. I hope nobody will post these kind of 'questions' any more. It's not CS spirit.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:01 AM
Points: 5,230,
Visits: 7,020
|
|
natalie.ignatieva (10/27/2010) Management studio shows me this script mostly in black meaning there is something wrong in the script even if it's completed successfully. The color coding is actually correct. The first [ character starts a table name that only ends at the final ], so everything in between them is part of the table name. Black is the default color used for (a.o.) table names. Please read the rest of the discussion for a more comprehensive explanation (and for many people agreeing with our dislike of the question)
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 9:38 AM
Points: 236,
Visits: 244
|
|
The color coding is actually correct. The first [ character starts a table name that only ends at the final ], so everything in between them is part of the table name. Black is the default color used for (a.o.) table names. Please read the rest of the discussion for a more comprehensive explanation (and for many people agreeing with our dislike of the question)
Yes, the color is correct, but I didn't have a chance to copy the script, so I had to type it. I missed ] in the line with 'while' because you don't expect developers to create tables with such weird names and thought it was typo or something. but even if I didn't miss it and executed the statement, I would see that author just wanted to create a table with such weird name. My point is that if you have your app generating these kind of statements and you try to understand what actually is wrong (yes, author wanted to look us for some errors in the script as if it's supposed actually run infinite loop or begin transaction), anyway you copy it from profiler to studio, see 'BEGIN' and 'INSERT' in black and just then you look for syntax issues. As I understand the point of this question is to make us develop skills in typing scripts from the image and don't make errors, right? I failed. Am I a bad SQL developer after that?
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 2:01 AM
Points: 5,230,
Visits: 7,020
|
|
natalie.ignatieva (10/27/2010) As I understand the point of this question is to make us develop skills in typing scripts from the image and don't make errors, right? I failed. Am I a bad SQL developer after that? No. I fully agree with you that this question is totally useless.
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|