Hi
I use below store procedure that don't allow insert duplicate data in database in code column
ALTER procedure [dbo].[insertestate1]
@position nvarchar(max)
,@Transfer nvarchar(20)
,@Type nvarchar(20)
,@Behcode nvarchar(10)
,@Measure varchar(20)
,@code varchar(20)
,@id int =0
,@Success VARCHAR(10) OUTPUT
AS BEGIN
IF NOT EXISTS(SELECT behcode FROM Estate_p WHERE code = @code)
BEGIN
INSERT INTO Estate_p
(
position
,[Type]
,Transfer
,Code
,behcode
)
VALUES
(
@position
,@Type
,@Transfer
,@code
,@Behcode
)
SET @Success = 'TRUE'
END
ELSE
SET @Success = 'FALSE'
END
and this is my other SP that I define Condition ,and according to that condition it update or insert data in dataabase
USE [behtop]
GO
/****** Object: StoredProcedure [dbo].[insertestate] Script Date: 10/04/2012 11:36:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[insertestate]
@TimeT varchar(10)
,@Description nvarchar(max)
,@Transfer nvarchar(20),
@Type nvarchar(20)
,@Behcode nvarchar(10)
,@Measure varchar(20)
,@code varchar(20)
,@id int =0
AS BEGIN
IF @id > 0 AND EXISTS(SELECT behcode FROM Estate_p WHERE id=@id)
BEGIN
UPDATE Estate_p
SET
TimeT=@TimeT
,Description=@Description
,Transfer=@Transfer
,Type=@Type
,Measure=@Measure
,Code=@code
WHERE BehCode=@Behcode and ID=@id
SELECT @id
END
ELSE
BEGIN
INSERT INTO Estate_p(TimeT,Transfer,Type,Measure,code)
VALUES(@TimeT,@Transfer,@Type,@Measure,@code)
SELECT SCOPE_IDENTITY()
END
END
in first SP @code parameter is column in table that I don't want accept duplicate value and condition of that is:
IF NOT EXISTS(SELECT behcode FROM Estate_p WHERE code = @code)
and in second SP I have @code parameter that I don't want it insert duplicate data on it too
but here condition is
IF @id > 0 AND EXISTS(SELECT behcode FROM Estate_p WHERE id=@id)
now I want merg two SP
How I can do it?
Best Regards