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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Scheduling an Upload and Deleting duplicate rows

Author  Topic 

flanz_g
Starting Member

22 Posts

Posted - 2006-11-05 : 13:04:28
Hi,
New to this Database and this forum as I am I would like to ask for a couple of prompts. My SQL2000 tables are ready and I need to schedule Daily upload of .txt files. These contain a rolling 7Days of Stats.
Q1: How best to schedule the automiatic uploading of this data to the respective Tables in SQLServer.(Field names are identical), and
Q2: How to schedule a Daily Deletion of those rows which are in the tables already (Each day 6 Days must be Deleted and 1 kept)

Appreciate your help,

Gezza

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-05 : 17:02:39
You can use DTS or BCP or BULK INSERT to import data into the database and schedule it using SQL Agent


KH

Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-11-06 : 00:42:10
quote:

How to schedule a Daily Deletion of those rows which are in the tables already (Each day 6 Days must be Deleted and 1 kept)



Wirte the trigger for it, so that it doesnt allow the duplicate rows to be inserted into the database.

or have some contraints on the table which may prevent from uploading the duplicates rows.

or you can schedule the Job for doing this. you can find the query for it on the following link

http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256


Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

flanz_g
Starting Member

22 Posts

Posted - 2006-11-06 : 05:57:52
Thanks for your good replies. Will be working on your answers later today, hopefully.
Go to Top of Page

flanz_g
Starting Member

22 Posts

Posted - 2006-11-07 : 07:56:34
quote:
Originally posted by khtan

You can use DTS or BCP or BULK INSERT to import data into the database and schedule it using SQL Agent


KH





Hi, I have tried to get more information on DTS and BCP from help menu but this does not come up. Please could you explain a bit how this works and which function would I need to set up and schedule the SQL agent? many Thanks.
Go to Top of Page

flanz_g
Starting Member

22 Posts

Posted - 2006-11-07 : 08:08:30
quote:
Originally posted by chiragkhabaria

quote:

How to schedule a Daily Deletion of those rows which are in the tables already (Each day 6 Days must be Deleted and 1 kept)



Wirte the trigger for it, so that it doesnt allow the duplicate rows to be inserted into the database.

or have some contraints on the table which may prevent from uploading the duplicates rows.

or you can schedule the Job for doing this. you can find the query for it on the following link

http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256


Chirag

http://chirikworld.blogspot.com/



quote:
Originally posted by darrendorlando

http://com-hpdevelopersolutions-2s.wwwa.com/members/remoteLoginCheck.cfm?id=MTMzMDAsYmxhY2tmaW4sL21lbWJlcnMvZXF1aXBtZW50L2luZGV4LmNmbQ_


This works for me and is way more efficient! Give'r a try, but remember to back up first and test the results to make sure you what you are expecting happens!


DELETE FROM [Table with Duplicates]
WHERE [Primary Key Field] IN
(
SELECT a.[Primary Key Field]
FROM [Table with Duplicates] a,
[Table with Duplicates] b

WHERE a.[Primary Key Field]!= b.[Primary Key Field] -- i.e. Userkey
AND a.[Value to check]= b.[Value to Check] -- i.e. Lastname
AND a.[Second Value to Check] = b.[Second Value to Check] -- i.e. Firstname
AND a.[Primary Key Field] < b.[Primary Key Field] -- i.e. Userkey
)


dd
ddorlando@gmail.com



Hi Chirag,
Have found the script I need I think but
Pardon ignorance could you explain the FROM clause
"...FROM
[Table with Duplicates] a,
[Table with Duplicates] b..."

What do "a" and "b" stand for?
Do I undersand that in order to Delete Dups I need 1st to CREATE a separate table via Import .txt and then, before Apending it to the main table, run a query comparing both and Deleting rows which are the same in each?
If this job is Scheduled for each Day will it overwrite the Temp table automatically each time with new data? Or do I need to write another SQL ro remove it or such like?

When you say write a trigger. Is it a menu function somewhere or is a trigger simply a freehand SQL element?

Please advise if you can.
Cheers, Gezza

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-09 : 10:23:29
a and b are alias names for the tables
If you worry about duplicates, why dont you filter and send only valid data to table?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -