Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
paultervit
Starting Member
10 Posts |
Posted - 2004-07-19 : 04:34:23
|
| HelloI am trying to insert values into a table for every row that does not have a related value in another table i.e. I need to insert a password history row into every row where one does not already exist for each UaserId in the user id table. Any ideas how this is done.CheersPaul |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-07-19 : 05:07:35
|
| USE NOT EXISTS.EG.CREATE TABLE #Test1(ColID INT, ColStuff VARCHAR(20));CREATE TABLE #Test2(ColID INT, ColStuff VARCHAR(20));INSERT INTO #Test1 VALUES(1, 'Test 1')INSERT INTO #Test1 VALUES(2, 'Test 2')INSERT INTO #Test1 VALUES(3, 'Test 3')INSERT INTO #Test1 VALUES(4, 'Test 4')INSERT INTO #Test1 VALUES(5, 'Test 5')INSERT INTO #Test2 VALUES(1, 'Test 1')INSERT INTO #Test2 VALUES(3, 'Test 3')INSERT INTO #Test2 VALUES(5, 'Test 5')SELECT * FROM #Test1 ORDER BY 1SELECT * FROM #Test2 ORDER BY 1INSERT INTO #Test2SELECT a.ColID, a.ColStuffFROM #Test1 aWHERE NOT EXISTS(SELECT b.ColID FROM #Test2 b WHERE a.ColID = b.ColID)SELECT * FROM #Test1 ORDER BY 1SELECT * FROM #Test2 ORDER BY 1Duane. |
 |
|
|
paultervit
Starting Member
10 Posts |
Posted - 2004-07-19 : 05:25:43
|
| Thanks :) |
 |
|
|
|
|
|