-
November 15th, 2007, 01:23 AM
#1
Error Message
I've got a procedure like this..
Code:
CREATE PROC dbWBS_sp_ExecuteQuery
(
@QueryString VARCHAR(8192),
@ErrMsg VARCHAR(512) OUTPUT
)
AS
BEGIN
EXEC @QueryString
END
Now if there is any error in the querystring I want to store that error message in this variable @ErrMsg. How can I accompalish this??
Thanks in Advance
-
November 15th, 2007, 02:34 AM
#2
-
November 15th, 2007, 07:54 AM
#3
Re: Error Message
Originally Posted by andreasblixt
SQL Server 2000 or 2005?
2005
-
November 15th, 2007, 08:38 AM
#4
Re: Error Message
Try this:
Code:
CREATE PROCEDURE uspTryExecute
@QueryString nvarchar(max),
@Error nvarchar(2048) = NULL OUTPUT
AS
BEGIN TRY
EXECUTE(@QueryString);
END TRY
BEGIN CATCH
SET @Error = ERROR_MESSAGE();
END CATCH;
GO
DECLARE @Message nvarchar(2048);
EXEC uspTryExecute N'SELECT a, b, c FROM NonExistentTable;', @Message OUT;
SELECT @Message;
GO
Last edited by andreasblixt; November 15th, 2007 at 08:41 AM.
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
|
Click Here to Expand Forum to Full Width
|