我有两个表:Table1和Table2。 它们之间有两个共同的列:ID,Name。
对于Name列,它们具有相同的值:A,B和C.
我需要执行检查,在执行SP后,它们将在Name列中为特定值具有相同的ID。 (A的ID相同,B的ID相同,C的ID相同)
这不是重复数据。表2是该过程所需的临时表。
我知道一种方法可以做到这一点,但想知道最有效和最简单的方法。
以下是我现在正在做的事情
DECLARE @Table1_id NVARCHAR(150)
DECLARE @Table2_id NVARCHAR(150)
SELECT @Table1_id = Tag_id FROM Tag WHERE Name = 'A'
SELECT @Table2_id = Tag_id FROM Tag_Imp WHERE Name = 'A'
IF @Table1_id = @Table2_id
BEGIN
PRINT 'Test Passed: ID of "A" is updated'
END
ELSE
PRINT 'Test Failed: ID of "A" is not updated'
SELECT @Table1_id = Tag_id FROM Tag WHERE Name = 'B'
SELECT @Table2_id = Tag_id FROM Tag_Imp WHERE Name = 'B'
IF @Table1_id = @Table2_id
BEGIN
PRINT 'Test Passed: ID of "B" is updated'
END
ELSE
PRINT 'Test Failed: ID of "B" is not updated'
SELECT @Table1_id = Tag_id FROM Tag WHERE Name = 'C'
SELECT @Table2_id = Tag_id FROM Tag_Imp WHERE Name = 'C'
IF @Table1_id = @Table2_id
BEGIN
PRINT 'Test Passed: ID of "C" is updated'
END
ELSE
PRINT 'Test Failed:ID of "C" is not updated'