Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 RAISERROR Help

Author  Topic 

tomex1
Starting Member

47 Posts

Posted - 2008-08-11 : 19:59:14
Hello All,
I am trying to use RAISERROR to print a custom error message but it doesn't seem to be working. I am using it in this procedure so that if @ContactCount is not qual to 1 i want to print a custme eror message but it doesn't appear to do anything. Please helpl :

USE [wce_sqlexpress]
GO
/****** Object: StoredProcedure [dbo].[history_proc] Script Date: 08/11/2008 19:44:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[history_proc]
@recordedtime datetime,
@recordedfor varchar(16),
@subject varchar(50),
@notes text,
@uniqueid varchar(16),
@etable varchar(100),
@utable varchar(100),
@contact varchar(100),
@emailaddress nvarchar(75),
@htype varchar(20)

AS

declare @entityid varchar(16)
declare @recordmanager varchar(16)
declare @ContactCount int

SET NOCOUNT ON

SET @ContactCount = (select count(*) from wce_contact where emailaddress = @emailaddress)
IF @ContactCount = 1
BEGIN
set @entityid = (select UNIQUEID from wce_contact where emailaddress = @emailaddress)
set @recordmanager = (select wce_sys..wces_users.UNIQUEID from wce_sys..wces_users where wce_sys..wces_users.WCE_UID = @recordedfor and wce_sys..wces_users.WCE_ALIAS = 'wce_sqlserver')

insert into wce_linkto (LEntityID, LETableName, LUniqueID, LUTableName)

VALUES (@entityid, @etable, @uniqueid, @utable)

SEt NOCOUNT OFF

insert into wce_history (UNIQUEID, RECORDEDTIME, RECORDEDFOR, SUBJECT, NOTES, HTYPE)

VALUES (@uniqueid, @recordedtime, @recordmanager, @subject, @notes, @htype)

END

ELSE
BEGIN
RAISERROR (50001,1,1)
END


sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-08-11 : 22:33:23

Like this:

IF @ContactCount <>1
BEGIN
RAISERROR ('An error occured with contactcount',10,1)
END
Go to Top of Page

tomex1
Starting Member

47 Posts

Posted - 2008-08-12 : 02:03:06
quote:
Originally posted by sodeep


Like this:

IF @ContactCount <>1
BEGIN
RAISERROR ('An error occured with contactcount',10,1)
END


Go to Top of Page

tomex1
Starting Member

47 Posts

Posted - 2008-08-12 : 02:03:07
quote:
Originally posted by sodeep


Like this:

IF @ContactCount <>1
BEGIN
RAISERROR ('An error occured with contactcount',10,1)
END




Hi Sodeep,
I tried that but SQL Server is not printing the custom error message. This is the message I got:
"Could not save to database.(Unknown error:Database returns an empty error message.)(SyncFolder)

Go to Top of Page
   

- Advertisement -