-
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?
-
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?
-
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.
-
@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'?
-
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
-
Forum Rules
|
|