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)
 Procedure Issue

Author  Topic 

tomex1
Starting Member

47 Posts

Posted - 2008-08-04 : 04:53:20
Hello all,
I have a procedure which runs when a button is clicked in Microsoft Outlook. Basically, the procedure is meant to update a record in the database and it works fine. I just realised that when the 'Select' statement in the procedure finds more than 1 record in the database, it throws an error message.

This is simply due to the fact that it doesn't know which of the records to insert into. My question is this-

How do I control the precedure so that if there are more than one contact with the same name, it should insert into all the three contacts?

I know that's going to be buggy from the user's point of view but I can't think of any other solution at the moment and I am open to your suggestion. Here is the procedure I would like to add the 'IF' statement into:

USE [demo]
GO
/****** Object: StoredProcedure [dbo].[activity_proc] Script Date: 08/04/2008 09:46:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[activity_proc]
@createtime datetime,
@createuser varchar(16),
@schedulefor varchar(16),
@duration numeric(10,0),
@subject varchar(50),
@notes text,
@atype varchar(12),
@uniqueid varchar(16),
@etable varchar(100),
@utable varchar(100),
@contact varchar(100)

AS
declare @contactid varchar(16)
declare @schedule varchar(16)
declare @entityid varchar(16)
declare @creationtime datetime
set @contactid = (select UserID from wce_contact where contact = @createuser)
set @schedule = (select UserID from wce_contact where contact = @createuser)
set @entityid = (select UNIQUEID from wce_contact where contact = @contact)


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

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

insert into wce_activity (UNIQUEID, CREATEUSER, SCHEDULEFOR, STARTTIME, DURATION, SUBJECT, NOTES, ATYPE)

VALUES (@uniqueid, @contactid, @schedule, @createtime,@duration, @subject, @notes, @atype)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-04 : 13:16:00
duplicate

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=107404
Go to Top of Page
   

- Advertisement -