Pages

Tuesday, April 12, 2011

Stored Procedure which automatically avoid Duplicate records....

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go




CREATE PROCEDURE [dbo].[Add_Home]
(
@ID BIGINT=NULL,
@Title varchar(MAX)=NULL,
@Description VARCHAR(max)=NULL,
@Status VARCHAR(5)=NULL,
@ErrorMsg VARCHAR(10) = NULL


)
AS
BEGIN

IF NOT EXISTS (SELECT * FROM Programme WHERE Title = @Title)
BEGIN
SET @ErrorMsg =@Title + ' Already Exists'
RAISERROR (@ErrorMsg,11,1)
return
END

ELSE IF(@Status='I')
BEGIN
INSERT INTO dbo.Home
( Title, Description )
VALUES ( @Title,@Description)
END
END

No comments:

Post a Comment