我的问题是我想插入值而不重复值。
ALTER PROCEDURE [dbo].[SD_Sproc_Result]
-- Add the parameters for the stored procedure here
@employeeid varchar(100),
@providercode varchar(100)
AS
BEGIN
Insert into TR_employeesprovidercode (employeeid, providercode) values
(@employeeid, @providercode)
END
最佳答案
尝试这个:
IF NOT EXISTS(SELECT * FROM TR_employeesprovidercode
WHERE employeeid = @employeeid
AND providercode = @providercode)
BEGIN
Insert into TR_employeesprovidercode (employeeid, providercode)
values (@employeeid, @providercode)
END
或者,您可以在包含employeeid和providercode两列的表上创建唯一约束。
ALTER TABLE myTable
ADD UNIQUE (employeeid, providercode);