September 26, 2006 at 2:04 pm
TableOne:
AcctNo
A
B
C
TableTwo:
A
C
INSERT INTO TableOne
(AcctNo)
SELECT
AcctNo
FROM TableTwo
--WHERE TableOne.AcctNo <> TableTwo.AcctNo ???
September 26, 2006 at 3:14 pm
You want to insert into TableTwo the values that exist in TableOne, but not yet in TableTwo? If so, you need an OUTER JOIN like this:
declare @TableOne table (AcctNo char(1))
declare @TableTwo table (AcctNo char(1))
INSERT INTO @TableOne
SELECT 'A' UNION ALL
SELECT 'B' UNION ALL
SELECT 'C'
INSERT INTO @TableTwo
SELECT 'A' UNION ALL
SELECT 'C'
INSERT INTO @TableTwo
SELECT One.AcctNo
FROM @TableOne One
LEFT JOIN @TableTwo Two
ON One.AcctNo = Two.AcctNo
WHERE Two.AcctNo IS NULL
SELECT *
FROM @TableTwo
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply