views:

175

answers:

2

I'm building a script to get all the triggers in the document, but I want to include newlines. I'm copying and pasting this into excel in order to then quickly generate some mandated documentation, but all the contents from the text column end up being generated without newlines.

The line I'm currently using, which produces truncation in results to file is:

SELECT OBJECT_DEFINITION(sys.objects.object_id)
FROM sys.objects 
WHERE type = 'TR'
+2  A: 
Tools->Options->Query Results->Results to file

No copy paste needed :)

jvenema
I'm getting truncation using the method above with my query.
Orion Adrian
In the dialog jvenema mentions, set "Maximum number of characters" to a larger value like 1024.
Dour High Arch
+1  A: 

For one, don't use syscomments on SQL Server 2005+. Use sys.sql_modules or OBJECT_DEFINITION. The datatype in syscomments in nvarchar(4000) which means truncation.

If you're in:

  • "Results to grid", you'll never have newlines
  • "Results to text", you'll have truncation (in tools..options somewhere)

So, why not use one of these techniques:

  • bcp or sqlcmd using OBJECT_DEFINITION on sys.objects to generate a plain text file?
  • use a SQL query in Excel?
  • SMO?
  • "Results to file" (as jvenema mentioned)?
gbn
There isn't truncation, syscomments just adds additional rows to cover it all.
Orion Adrian
And that makes it Ok to use? it's a bad habit since SQL 2005. Anyway, I've offered ideas on how to get your newlines back...
gbn
I am getting truncation with OBJECT_DEFINITION and with sys_modules.
Orion Adrian
Only because you're not reading the data correctly when cutting and pasting out of SSMS
gbn
I'm viewing the truncation in SSMS before I make the copy.
Orion Adrian
SSMS is truncating, not OBJECT_DEFINITION or sys_modules. There is a setting in tools..options.. that changes when long text data truncates, but I can't recall where exactly.
gbn
I found something that works. Thanks.
Orion Adrian