Results 1 to 5 of 5

Thread: Printing (T-SQL)

  1. #1
    Join Date
    Sep 2012
    Posts
    11

    Printing (T-SQL)

    Hi Guys,

    I tried to run below query

    BEGIN TRY
    SELECT 1/0
    print 'Hello'
    END TRY
    BEGIN CATCH
    print 'CATCH entered.'
    END CATCH
    but it returned only empty column and it should print 'CATCH entered'

    Could You please help me with that?

  2. #2
    Join Date
    Sep 2012
    Posts
    11
    I have founded how it should look like:

    BEGIN TRY
    declare @var int = 1/0
    print 'Hello'
    END TRY
    BEGIN CATCH
    print 'CATCH entered.'
    END CATCH
    Could You please explain to my why it should like like above?

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Both work. The message is printed on Messages tab on the result window, because of SELECT statement the first window is for resultset. In second post, you don't have SELECT so there is only Message tab in the result.

  4. #4
    Join Date
    Sep 2012
    Posts
    11
    @skhanal

    So how should look like the query in first post to print 'CATCH entered'?
    I know if I will use select instead of print in CATCH block I will see two results windows.
    What if I want to return only one result window with mentioned 'CATCH entered'?

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can change the management studio setting to "Results to Text"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •