Working with Long Strings by Jeff Moden

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
How Did I Steal Your Database Mostafa
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Introduction to Python
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Bell Ringer What types are numbers are there is the python programming language?
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Intro to More Controls in C#. C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
SQL Spackle #1 Jeff Moden 19 May About Your Speaker Mostly Self Trained Started with SQL Server in 1995 More than 25,000 posts on SQLServerCentral.com.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
Conversion Functions.
SQL for SQL Server, C13© 2002, Mike Murach & Associates, Inc. Slide 1.
Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall. 1 Skills for Success with Office 2010 Vol. 1, 2e PowerPoint Lecture to Accompany.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Creating a Workbook Part 1
Word Lesson 1 Microsoft Word Basics
Word Lesson 1 Word Basics
The Second C++ Program Variables, Types, I/O Animation!
Data Virtualization Tutorial: Custom Functions
More about comments Review Single Line Comments The # sign is for comments. A comment is a line of text that Python won’t try to run as code. Its just.
Chapter 6 JavaScript: Introduction to Scripting
Microsoft Office Illustrated Introductory, Windows XP Edition
Topic Pre-processor cout To output a message.
What Actions Do We Have Part 1
Data Virtualization Tutorial: XSLT and Streaming Transformations
Chapter 2, Part I Introduction to C Programming
Dynamic SQL: Writing Efficient Queries on the Fly
Bulk Editing Catalogue Records
SQL Saturday Pittsburgh
mysql and mysql workbench
Chapter 18 I/O in C.
Introduction to Objects
Intro to PHP & Variables
Microsoft Office PowerPoint 2010 INSERTING GRAPHIC OBJECTS
STRUCTURED QUERY LANGUAGE
{. “speaker”:. “Emanuele Zanchettin”,. “session” :
Dynamic SQL for the DBA by Jeff Moden
Introduction to C++ Programming
WEB PROGRAMMING JavaScript.
Microsoft Excel 101.
Week 9 – Lesson 1 Arrays – Character Strings
Dynamic SQL: Writing Efficient Queries on the Fly
SQLCmd Mode The T-SQL Easy Button
Created by: Jennifer Tyndall Spring Creek High School
Tally Function with Error Checking by Jeff Moden
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Views in Word 2010.
Lesson 15 Working with Tables
Word Lesson 1 Word Basics
Get More Than CRUD From Your ORM
Microsoft Official Academic Course, Microsoft Word 2013
Output Manipulation.
Type the name of character here
CSC 1051 – Data Structures and Algorithms I
Key Applications Module Lesson 14 — Working with Tables
Chapter 2 part #1 C++ Program Structure
PYTHON - VARIABLES AND OPERATORS
Introduction to Objects
Presentation transcript:

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

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 http://www.sqlservercentral.com/Authors/Articles/Jeff_Moden/80567/ 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 2013 © Copyright by Jeff Moden - All Rights Reserved

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 2013 © Copyright by Jeff Moden - All Rights Reserved

The Problem with Viewing Long Dynamic SQL

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 2013 © Copyright by Jeff Moden - All Rights Reserved

Sloshing

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 2013 © Copyright by Jeff Moden - All Rights Reserved

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... DECLARE @Cmd VARCHAR(8000); SELECT @Cmd = 'sqlcmd -E -S "VAIO" -h-1 -s" " -W -Q ' + '"SELECT * FROM master.sys.master_files" -o ' + 'c:\temp\QueryResults.txt' EXEC xp_cmdshell @Cmd --===== 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 2013 © Copyright by Jeff Moden - All Rights Reserved

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 2013 © Copyright by Jeff Moden - All Rights Reserved

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

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