Thread: Asp Code help
View Single Post
Old 03-26-2003, 04:47 AM   #7 (permalink)
berklee
Registered User
 
Join Date: Mar 2003
Posts: 18
berklee is on a distinguished road
Oh! I almost forgot...

You can put some logic in a stored procedure to test for the existence of the record, and return something back to the ASP page to let you know what happened.

something like....

CREATE PROCEDURE dbo.up_MyTable_SmartDelete(@tableid integer)

AS

BEGIN

declare @result integer

IF EXISTS(SELECT tableid from MyTable where tableid = @tableid)
BEGIN
select @result = (SELECT tableid from MyTable where tableid = @tableid)
END

IF NOT EXISTS(SELECT tableid from MyTable where tableid = @tableid)
BEGIN
select @result = 0
END

return @result

END

When you try and delete something from this table using the above proc, you'll always get a value back as a one field, one row recordset. If the value is something other than 0, you know it's already in the table. So from there, you can just use a simple IF statement to give the user hell for trying to put the same stuff in there twice.

berklee is offline   Reply With Quote