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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Messages for User Using Triggers

Author  Topic 

josh2009
Yak Posting Veteran

81 Posts

Posted - 2009-09-15 : 11:53:38
Hi,

Trying to validate user entry for certain fields in a purchased application. I've tried using sp_addmessage in my trigger to try and show a message for the users if they forget to enter a doctor's name. My trigger is as follows -

USE [Test]
GO
/****** Object: Trigger [dbo].[BLGH_TR_Event_Cath] Script Date: 09/11/2009 15:56:27 ******/
EXEC sp_addmessage 50002, 16,
N'Interventional MD expects a value. Please enter a physician name.';
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID ('BLGH_TR_Event_Cath,'TR') IS NOT NULL
DROP TRIGGER BLGH_TR_Event_Cath;
GO
CREATE TRIGGER [dbo].[BLGH_TR_Event_Cath]
ON [dbo].[Event_Cath]
AFTER INSERT, UPDATE
AS

Declare @SSEventCathID int, @CathAttending2nd varchar(40)

Select @SSEventCathID = Event_Cath.SS_Event_Cath_ID,
@CathAttending2nd = Event_Cath.CathAttending2nd
From Event_Cath, Inserted
Where Event_Cath.SS_Event_Cath_ID = Inserted.SS_Event_Cath_ID

/* Check @CathAttending2nd */
Begin
If Inserted.CathAttending2nd = ' '
RAISERROR(50001,1,16)
End

Any help would be greatly appreciated. Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-15 : 18:45:03
You need to do this in your application and not in SQL Server. If you are unable to modify the code, then you'll need to contact the vendor to add this feature.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-09-16 : 12:48:14
most of front end tools have ability to do client side validations. which is tool you're using?
Go to Top of Page
   

- Advertisement -