Insert Statment with Case for avoid duplicate record insertion
- by rama
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