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 |
jgrant
Yak Posting Veteran
69 Posts |
Posted - 2007-03-28 : 14:50:06
|
Okay, I have written a query that creates some data from several other tables and databases. It works well populating into a new table every night. But I went to back build some data from a year ago and all of a sudden the query was creating duplicates. I checked the stored procedure that runs every night and it was not creating dupes so, all in all it must work. So the problem must lie in the date loop that I have created for the backbuild. Here it is here. Let me know if something is wrong with it.Declare @StartDate datetimeDeclare @EndDate DatetimeSet @StartDate = '2006-04-01'Set @EndDate = '2006-04-01 23:30:00'While @StartDate < '2006-05-01'begin <perform work here>set @startdate = dateadd(dd,1,@startdate)set @enddate = dateadd(dd,1,@enddate)endThe Yak Village Idiot |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-28 : 15:02:05
|
What is the work performed?Peter LarssonHelsingborg, Sweden |
 |
|
jgrant
Yak Posting Veteran
69 Posts |
Posted - 2007-03-28 : 15:17:49
|
its really long. Its work performed from a pos software. I will send it to you if you want with apologies because I am just learning to program so it may be a little confusing. There are several loops in there as well. On its own, when run without the date loop it does not create loops. Let me know if you would like me to send it to you via email.The Yak Village Idiot |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-28 : 15:38:23
|
No, please. I get enough emails as it is.The loop above does not create dupes with dates. Maybe <the work here> code do?Or are several users running this stored procedure?Peter LarssonHelsingborg, Sweden |
 |
|
jgrant
Yak Posting Veteran
69 Posts |
Posted - 2007-03-28 : 16:59:17
|
lol, okay Peter. Um the stored procedure works as its supposed to. I essentailly wrapped the date loop around the stored procedure and then started getting duplicate records. So, somehow the script is maybe running several times within the date loop.The Yak Village Idiot |
 |
|
|
|
|
|
|