下面用于插入/更新sql数据库的存储过程
ALTER PROCEDURE [dbo].[uspInsertorUpdate]
@dp char(32),
@dv char(32),
@e_num char(12),
@mail varchar(50),
@emerg char(32),
@opt1 char(16),
@stat char(20),
@e_id char(35),
@e_tit varchar(64),
@e_date datetime
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT 1 FROM [dbo].[sampleemployee] WHERE e_id= @e_id)
BEGIN
UPDATE [dbo].[sampleemployee]
SET dp = @dp,
dv = @dv,
e_num = @e_num,
mail = @mail,
emerg = @emerg,
opt1 = @opt1,
stat = @stat,
e_tit = @e_tit,
e_date = @e_date
WHERE e_id = @e_id
END
ELSE
BEGIN
INSERT INTO [dbo].[sampleemployee]( dp, dv, e_num, mail, emerg, opt1, stat, e_id, e_tit, e_date)
VALUES ( @dp, @dv, @e_num, @mail, @emerg, @opt1, @stat, @e_id, @e_tit, @e_date );
END
END;
但它只插入一行。但是,我有一组来自Oracle数据库的记录,我必须插入/更新,具体取决于e_id到SQA数据库。不确定需要更改的内容。
答案 0 :(得分:0)
条件语句看起来不错,但似乎@e_id与e_id不匹配。在这种情况下,我会编写更简单的语句用于调试目的:
IF EXISTS (SELECT 1 FROM [dbo].[sampleemployee] where e_id = 'some known value')
BEGIN
PRINT 'YES'
END
ELSE
BEGIN
PRINT 'NO'
END
也许这有助于指出你忽略的东西。 @e_id是否与e_id完全匹配,或者你有一些清理要做吗?