How can I reset a SELECT statement in the Messages panel in mgmt SQL Server studio from a stored procedure?

I can use the PRINT statement in a stored procedure to debug my code. I see the output on the Messages tab in SQL Server Management Studio. How can I reset one or more integer SELECT outputs to the Messages tab?

My stored procedure returns multiple output variables, so returning a single dataset here is not an option. I am afraid to find a good way to debug my complex procedures.

+5
source share
4 answers

, , , . . , NULL. , . :

Alter Procedure Foo(@Col1 int, @col2 varchar(20), @Debug Bit = NULL)
As
SET NOCOUNT ON

If @Debug = 1
  Begin
    Select * From SomeTable Where Col1 = @Col1
  End

-- The rest of your code here

, , 1 @Debug

+3

" ", " " , PRINT SELECT.

, :

  • -
  • \ \
+10

, . sp.

CREATE TABLE ##t1 (x int)
GO

CREATE PROCEDURE Foo AS
BEGIN
  TRUNCATE TABLE ##t1
  INSERT INTO ##t1 SELECT column FROM table;
END
GO

exec Foo;
select x from ##t1;
+2

? , , . "", . :

select 'checkpoint1',a,b,c from table1
....
select 'table @a', *  from @a
....
<actual query here>

, .

+1

All Articles