Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with Long Strings by Jeff Moden

Similar presentations


Presentation on theme: "Working with Long Strings by Jeff Moden"— Presentation transcript:

1 Working with Long Strings by Jeff Moden
Rainbow Lightning Working with Long Strings by Jeff Moden SPID Lightning Rounds, Detroit, Mi 12 September 2013

2 Your Speaker - Jeff Moden
17 years experience working with SQL Server Mostly Self Taught One of Leading Posters on SQLServerCentral.com More than 32,000 posts (heh… some are even useful) 30+ articles on the “Black Arts” of T-SQL Member since 2003 SQL Server MVP 2008 thru 2013 Winner of the “Exceptional DBA” award for 2011 Lead Application DBA, Data Architect, and SQL Mentor for Proctor Financial, Inc. SQL Server is both my profession and my hobby (Yeah, I know… I need to get a life ;-) Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

3 Agenda I call it “Rainbow Lightning” because it will allow us to see the “End of the Rainbow” where long strings are concerned. The Problem with Viewing Long Dynamic SQL An Easy Fix A Convenient Function Wrapping Long T-SQL Literals for Readability Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

4 The Problem with Viewing Long Dynamic SQL

5 The Display Problem To summarize the problem DEMOs
Print works fine but is limited to something less than 8,000 characters (4,000 if using NVARCHAR) Display to the Grid removes all formatting and converts to a single line DEMOs (See attached files) Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

6 Sloshing

7 What is “Sloshing”? It’s the Reverse of Concatenation
Allows splitting up of long strings for display/readability purposes Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

8 Examples Working with Long Strings
--===== The command must appear as a single line to xp_CmdShell -- (There's a TAB character between the empty double quotes) -- but it doesn't fit the screen (indicated by the dashed lines) EXEC xp_cmdshell 'sqlcmd -E -S "VAIO" -h-1 -s" " -W -Q "SELECT * FROM master.sys.master_files" -o c:\temp\QueryResults.txt' ; ===== This is one way to fix the problem but it does take some doing... VARCHAR(8000); = 'sqlcmd -E -S "VAIO" -h-1 -s" " -W -Q ' + '"SELECT * FROM master.sys.master_files" -o ' + 'c:\temp\QueryResults.txt' EXEC --===== The command must appear as a single line to xp_CmdShell but -- we can "split" the line up a lot more easily with "Sloshing". -- A backslash followed by presing the enter key is call "SLOSHING" EXEC xp_cmdshell 'sqlcmd -E -S "VAIO" -h-1 -s" " -W -Q "SELECT * FROM mas\ ter.sys.master_files" -o c:\temp\QueryResults.txt' Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

9 Quick Review Learned quick an easy way to display ALL of the Dynamic SQL using an XML trick. Created a ShowBigString function to make it even easier. Learned how to “Slosh” (unconcatenate) long strings for readability without having to create a variable, etc. Working with Long Strings 12 September © Copyright by Jeff Moden - All Rights Reserved

10 See me at the end of tonight’s presentations.
Q’n’A See me at the end of tonight’s presentations.

11 Working with Long Strings by Jeff Moden
Rainbow Lightning Working with Long Strings by Jeff Moden Thanks for Listening SPID Lightning Rounds, Detroit, Mi 12 September 2013


Download ppt "Working with Long Strings by Jeff Moden"

Similar presentations


Ads by Google