Dynamic SQL getting cut off with PRINT STATEMENT

Posted on 2012-08-22
Last Modified: 2012-08-22
I have a long stored procedure (dynamic sql) that I am trying to print out so I can debug it.  The SQL is contained in this variable - @sSQL.

When I run this PRINT statement, it keeps getting cut off:


How can I overcome this?  I am trying to determine how to print ranges.. for example, print the first 200 lines, then print lines 201-400, then print lines 401-600, etc.

Question by:jamesdean666
    LVL 142

    Accepted Solution

    DECLARE @stmp varchar(max)
    SET @stmp = ISNULL(@sSQL,'')
    WHILE @stmp <> ''
       PRINT LEFT(@stmp, 1000)
       SET @stmp = substring(@stemp, 1001, len(@stemp))

    Author Closing Comment

    Thanks so much!

    F.Y.I... For anyone subsequent viewers.. slight typo in solution.. @stemp = @stmp

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now