Created
July 28, 2016 14:34
-
-
Save dalenewman/d153485c0ac21ca6e158497ca1672e80 to your computer and use it in GitHub Desktop.
sp_log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
GO | |
-- you have to start procedure name with sp_ to make it global | |
CREATE PROCEDURE sp_log | |
@Message NVARCHAR(512), | |
@RowCount INT = null OUTPUT, | |
@Delimiter NCHAR(1) = N' ', | |
@PadChar NCHAR(1) = N'-' | |
AS | |
BEGIN | |
SET @RowCount = @@ROWCOUNT; | |
DECLARE @LogDate AS NVARCHAR(50); | |
DECLARE @RowCountPadded AS NCHAR(8); | |
SET @LogDate = CONVERT(NVARCHAR(50),GETDATE(),121); | |
SELECT @RowCountPadded = CASE @RowCount WHEN 0 THEN REPLICATE(@PadChar,8) ELSE REPLACE(STR(@RowCount, 8), SPACE(1), @PadChar) END; | |
SET @Message = @LogDate + @Delimiter + @RowCountPadded + @Delimiter + @Message; | |
RAISERROR (@Message, 0, 1) WITH NOWAIT; | |
END | |
GO | |
-- Mark it as system object | |
EXEC sys.sp_MS_marksystemobject sp_log | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dont forget to: GRANT EXECUTE ON OBJECT::[master].dbo.sp_log to public;