Insert Statment with Case for avoid duplicate record insertion
Posted
by
rama
on Stack Overflow
See other posts from Stack Overflow
or by rama
Published on 2012-06-12T04:19:03Z
Indexed on
2012/06/12
4:40 UTC
Read the original article
Hit count: 162
I have written the below SP for Precheck for Duplicate records before insert into Table . but it is not allow me yo write insert staement inside the CASE .
how can I write Stored Procedure for fist Check the value @Ordername into table After that if it is not present then it should inserted into Database .
CREATE PROCEDURE [Test Procedure ]
(
@section varchar(70),
@mark varchar(70),
@qty decimal(18,2),
@Weight decimal(18,2),
@dateupdateremark int,
@OrderName varchar(70)
)
AS
BEGIN
SET NOCOUNT ON;
select case(@OrderName)
when (select OrderName from dbo.tbl_insertxmldetails
where(@OrderName) not in (select OrderName from tbl_insertxmldetails))
then
insert into dbo.tbl_insertxmldetails
(Section, Mark, QTY,Weight,Dateupdateremark ,OrderName,SystemDate)
values
(@Section, @Mark, @QTY,@Weight, @Dateupdateremark,@OrderName,GETDATE())
else 'File already Exists'
end
© Stack Overflow or respective owner