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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-28 : 23:11:49
|
| Jerome writes "i have this code to populate my table.INSERT TKTimeEmp (COID,EmpID,TimeID) SELECT COID,EmpID,'T1' FROM TKTempEmpData WHERE COID = 'BF001'the problem is: How can i check if the data that i am inserting was already in the table(Data already exist)?" |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2003-09-29 : 00:34:09
|
| HiYou could use EXISTS to check :If NOT Exists (SELECT 1 FROM TKTimeEmp WHERE COID = 'BF001')INSERT blahDamian |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-09-29 : 03:33:47
|
| or (and I prefer select * rather than select 1 for existence checks)INSERT TKTimeEmp (COID,EmpID,TimeID) SELECT COID,EmpID,'T1' FROM TKTempEmpData tleft outer join TKTempEmpData t2on t.COID = t2.COIDand t.EmpID = t2.EmpIDand t2.TimeID = 'T1'WHERE t.COID = 'BF001'and t2.COID is null==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|