Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One approach might be to check if the proc is being run from SSMS and fire some <a href="http://weblogs.sqlteam.com/mladenp/archive/2008/10/16/Custom-user-configurable-SQL-Server-Profiler-events.aspx" rel="nofollow">Custom user configurable SQL Server Profiler events</a> if so. e.g.</p> <pre><code>CREATE PROC foo AS DECLARE @debug bit = CASE WHEN APP_NAME() = 'Microsoft SQL Server Management Studio - Query' THEN 1 ELSE 0 END DECLARE @userinfo nvarchar(128) DECLARE @userdata varbinary(8000) --Do some work here IF @debug = 1 BEGIN --Do some custom logging SET @userinfo = N'Some custom info' SET @userdata = CAST('Some custom data' AS varbinary(8000)) EXEC sp_trace_generateevent @eventid = 82 /*Use 82-91*/ ,@userinfo = @userinfo ,@userdata = @userdata END </code></pre> <hr> <p>Though in practice I usually use something like the below. Sometimes with additional code to log the message (and possibly step and status values) to a table depending on requirements. This would allow the "filterable" requirement to be met.</p> <p>This stops the message being printed out except if the <code>APP_NAME</code> indicates it is being run in (an English language version of) SSMS and uses <code>NOWAIT</code> so the message gets printed out immediately rather than waiting for the buffer to fill.</p> <pre><code>CREATE PROCEDURE [dbo].[PrintMessage] @message NVARCHAR(MAX), @PrependCurrentTime BIT = 0 AS IF APP_NAME() LIKE 'Microsoft SQL Server Management Studio%' BEGIN DECLARE @CurrentTimeString VARCHAR(30); SET @CurrentTimeString = '' IF @PrependCurrentTime = 1 BEGIN SET @CurrentTimeString = CONVERT(VARCHAR(19), GETDATE(), 20) + ' ' END RAISERROR('%s%s',0,1,@CurrentTimeString,@message) WITH NOWAIT END </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload