News for hackers. Stuff that matters.
Re:SQL Tips and Tricks by Semaphor on Wednesday September 25, 2024 @01:43AM (#41644036)
Regarding "Comment your code!": At least for MSSQL, it’s often recommended not to use -- for comments but instead /**/, because many features like the query store save queries without line breaks, so if you get the query from there, you need to manually fix everything instead of simply using your IDEs formatter.
Re:SQL Tips and Tricks by petters on Wednesday September 25, 2024 @02:20AM (#41644228)
That sounds like a bug in the query store
Re:SQL Tips and Tricks by regexman1 on Wednesday September 25, 2024 @02:15AM (#41644200)
I didn't realise that, great to know. Thanks!
Re:SQL Tips and Tricks by password4321 on Thursday September 26, 2024 @12:51AM (#41654648)
Are you able to cast as XML? I use that for OBJECT_DEFINITION, eg.

  select name,cast((select OBJECT_DEFINITION(object_id) for xml path('')) as xml) from sys.procedures  
This can be easier to straighten out since it preserves the newlines though other XML characters get mangled like > to >. One other option is VARBINARY plus something to un-hex it.