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 |
|
caterpillar
Starting Member
9 Posts |
Posted - 2006-07-21 : 16:17:32
|
| Hello All, I need to insert values in a table so that if a duplicate field comes for a record, it gets overwritten on the previous field and so on.I dont have to use unique key constraints to avoid duplicate entry of data.Any idea how to proceed....RegardsMonica |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-07-21 : 16:28:56
|
| Could you explain more, perhaps with a data example?Tara Kizer |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
caterpillar
Starting Member
9 Posts |
Posted - 2006-07-24 : 10:16:13
|
| Thanks Tara & Madhivanan.This is what i have done:----------------------------------------------------------------------if (select count(*) from table1 where field1=@param1) > 0 update table1 set field1=@param1elseINSERT INTO table1(field1,field2) VALUES (@param1,@param2)--field1 and field2 are of type varchar--there is no primary key in the table----------------------------------------------------------------------This has replaced all the existing values of field1 with param1.I hope it has given a better picture now. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-07-24 : 10:27:28
|
This code can be used to delete duplicates.DELETEFROM Table1WHERE Field1 = @Param1 AND Field2 = @Param2INSERT Table1 ( Field1, Field2 )VALUES ( @Param1, @Param2 ) Peter LarssonHelsingborg, Sweden |
 |
|
|
Q
Yak Posting Veteran
76 Posts |
Posted - 2006-07-24 : 10:28:49
|
| In your update statement should also be 'where field1= @param1' But this won't do a thing. If field1 is equal to @param1, then set field1 to @param1... Example: if field1 is 'a', then set field1 to 'a'... |
 |
|
|
|
|
|