Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Monday, August 23, 2010

How to check Record Exist in table before insert

Here i am explain you check if record is not exist in database then insert otherwise update the table.

CREATE PROCEDURE [dbo].[uspInst_Addupdate]
(
@InstId int,
@Inst varchar(50),
)
AS
BEGIN
IF @InstId=0
BEGIN
IF NOT EXISTS(SELECT * FROM InstMaster WHERE Inst= @Inst)
INSERT INTO InstMaster(Inst) VALUES(@Inst)
END
ELSE
BEGIN
UPDATE InstMaster
SET Inst= @Inst WHERE (Inst= @Inst)
END
END

Thanks & Regards
Santosh

No comments:

Post a Comment