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 |
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-08-13 : 13:24:54
|
| I want to be able to insert records from one table to another, but if if already exists I don't want to insert it. I have this, but it doesn't work:IF NOT EXISTS(SELECT * INTO tblForeverHUD FROM tblHUDdata)What is the proper way to do it? Thanks!Brenda |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-13 : 13:28:20
|
| will this suffice?if not exists(select ... from MyTable where some condition)begininsert into MyTable select ....endelsebegin-- something elseendGo with the flow & have fun! Else fight the flow :) |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-08-13 : 13:38:18
|
| But what do I put in the WHERE condition? I want everything to be inserted it it is not already in the table. Thanks!Brenda |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-08-13 : 13:44:32
|
| this will select the rows from SomeTable that are not in MyTable and insert them into MyTableinsert into MyTable(col1, col2, ...)SELECT col1, col2, ...FROM SomeTable t1WHERE NOT EXISTS (SELECT * FROM MyTable t2 WHERE t2.id = t1.id)will that be ok? :)Go with the flow & have fun! Else fight the flow :) |
 |
|
|
brendalisalowe
Constraint Violating Yak Guru
269 Posts |
Posted - 2004-08-13 : 14:10:43
|
That works perfect! Thanks bunches |
 |
|
|
|
|
|