Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:22:16+00:00 2026-05-27T10:22:16+00:00

I have a logging function in T-SQl similiar to this: CREATE PROCEDURE [logging] @PROCEDURE

  • 0

I have a logging function in T-SQl similiar to this:

CREATE PROCEDURE [logging]    
@PROCEDURE VARCHAR(50),
@MESSAGE VARCHAR(MAX)
AS
BEGIN
    PRINT @MESSAGE

END;
GO

I am able to call it like this:

execute logging N'procedure_i_am_in', N'log_message';

As my stored procedure names are a bit long winded, I want to write an alias or an inline function or so, to call the logging procedure for me, with the current procedure. Something like this (which is broken):

declare @_log varchar(max)
set @_log = 'execute logging N''procedure_i_am_in'', '
execute @_log N'MESSAGE!'

And i would put that alias at the top of each procedure.

What are your thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:22:17+00:00Added an answer on May 27, 2026 at 10:22 am

    Quite simple

    CREATE PROCEDURE [logging]    
       @PROCID int,,
       @MESSAGE VARCHAR(MAX)
    -- allows resolution of @PROCID in some circumstances
    -- eg nested calls, no direct permission on inner proc
    WITH EXECUTE AS OWNER
    AS
    BEGIN
        -- you are using schemas, right?
        PRINT OBJECT_SCHEMA_NAME(@PROCID) + '.' + OBJECT_NAME(@PROCID);
        PRINT @MESSAGE
    END;
    GO
    

    Then

    execute logging @@PROCID, N'log_message';
    

    MSDN on OBJECT_SCHEMA_NAME and @@PROCID

    Edit:

    Beware of logging into tables during transactions. On rollback, you’ll lose the log data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static logging function that uses StringBuilder to concatenate a bunch of
I use SQL Server 2005. I have a simple logging table that my web
I have the following function. When I try to create it on a webserver,
I have a custom logging function to log to the firebug console that looks
I'd like to have a reusable logging method or function that spits out the
I have a logging function that takes the calling object as a parameter. I
I have logging function as follows. logging.basicConfig( filename = fileName, format = %(levelname) -10s
I have a logging function that takes in a variable number of arguments and
I have logging function being called at several places throughout the code. To every
I have the next simple logging code: function log($exception) { error_log($exception->getMessage() . \n, 3,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.