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 |
|
hwood125
Starting Member
12 Posts |
Posted - 2008-08-25 : 10:07:01
|
| I am wondering what the best way would be to count the number of records that gets inserted into a table A from a variable table B that are not already in table A? The whole point is to avoid duplicates. I know primary keys would help but the primary keys get created based off of the date of the text file that gets inserted. So there is always a possibility of having duplicated records going through the text files. There are other steps that I would like to implement after this step depending wether the count is <> 0 is the ticket for now.Thanks! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-25 : 10:11:07
|
| didnt get the scenario fully. Will be inserting from text file or anothertable? first sentence says insert from table b then you say its from text files. Can you clarify? |
 |
|
|
hwood125
Starting Member
12 Posts |
Posted - 2008-08-25 : 10:14:39
|
| I will be inserting from a temp variable table into a table. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-25 : 10:14:53
|
| Make use of @@ROWCOUNTAlso, this forum is to post workable script and not to ask questionsMadhivananFailing to plan is Planning to fail |
 |
|
|
hwood125
Starting Member
12 Posts |
Posted - 2008-08-25 : 10:18:43
|
| I thought forums were to help people. The whole point of me posting my topic is to get help because I DIDN'T KNOW a workable script to use in this situation. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-08-25 : 10:25:15
|
| true. but this specific forum is for posting scripts that work and are helpfull to other people.that's why i'm moving this from script library._______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.0 out! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-25 : 10:27:42
|
quote: Originally posted by hwood125 I thought forums were to help people. The whole point of me posting my topic is to get help because I DIDN'T KNOW a workable script to use in this situation.
You can post it no problem but not HERE...What Madhi told was not to post in this forum which is for scripts. you've other specific forums here like sql 2005,sql 2000,... where you can post. this forum is for posting scripts only.Now your questions answerIf you want to avoid duplicates just check if combination already exists before insertion like belowINSERT INTO TableASELECT fieldsFROM @TableVariable tLEFT JOIN TableA aON a.uniquefieldcombination=t.uniquefieldcombinationWHERE a.uniquefieldcombination IS NULL |
 |
|
|
|
|
|