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 |
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2005-06-24 : 16:00:48
|
| SORRY! This is a crosspost from the administration forum, but this is where I should have posted...sorry that it is in both places, please reply here... The Select Statement above would return a record like soProjectID :: EventID :: EstimatedCompletionDate :: LeadTime1 :: 1 :: :: 101 :: 2 :: :: 201 :: 3 :: :: 5So, what I need to do here is to take @CustomerShipDate, which is passed into the stored proc, the count the days backward. So, if @CustomerShipDate were 07/25/2005, and I were calculating for EventID 3. I could say DateAdd(day, LeadTime(which is 5), @CustomerShipDate).But, now, how would I get the rest of the values?? Because now, for EventID 2, I need to sayDateAdd(day, LeadTime(EventID 3 LeadTime which is 5 MINUS EventID 2 LeadTime which is 20 ), @CustomerShipDate)Does this makes sense? Thanks for lookingINSERT INTO ProjectEvent(ProjectID, EventID, EstimatedCompletionDate, LeadTime)SELECT @ProjectID, CompanySeasonProductTemplate.EventID, (Calculate Estimated CompletionDate Here), Event.LeadTimeFROM CompanySeasonProductTemplate INNER JOINEvent ON CompanySeasonProductTemplate.EventID = Event.EventIDWHERE (CompanySeasonProductTemplate.CompanyID = @CompanyID)AND SeasonID Is NullAND ProductCategoryID Is NullORDER BY EventOrder |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-06-24 : 18:41:00
|
| I've had to guess a little as to your table structures, but this is a potential way to do it:INSERT INTO ProjectEvent(ProjectID, EventID, EstimatedCompletionDate, LeadTime)SELECT @ProjectID, CompanySeasonProductTemplate.EventID, DATEADD(d, Event.Leadtime, Z.CSD), Event.LeadTimeFROM CompanySeasonProductTemplate INNER JOINEvent ON CompanySeasonProductTemplate.EventID = Event.EventIDLEFT JOIN (SELECT @CustomerShipDate as CSD, CompanyID, MAX(EventID) AS MaxEventID FROM CompanySeasonProductTemplate GROUP BY CompanyID) AS Z ON CompanySeasonProductTemplate.CompanyID = Z.CompanyID AND CompanySeasonProductTemplate.EventID = Z.MaxEventID WHERE (CompanySeasonProductTemplate.CompanyID = @CompanyID)AND SeasonID Is NullAND ProductCategoryID Is NullORDER BY CompanySeasonProductTemplate.EventID DESCDECLARE @CompletionDate datetimeSELECT @CompletionDate = EstimatedCompletionDate FROM ProjectEvent WHERE EstimatedCompletionDate IS NOT NULLUPDATE ProjectEvent SET @CompletionDate = EstimatedCompletionDate = DATEADD(d, leadtime, @CompletionDate)WHERE EstimatedCompletionDate IS NULLThe INSERT just inserts the the EstimatedCompletionDate, based on the biggest EventID. The UPDATE updates the rest of the dates in descending order. The columns might be a little off, but I think you'll get the general idea. |
 |
|
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2005-06-25 : 11:25:15
|
| This actually ended up working. I did not figure this out myself, someone on another board did. I very much appreciate the help here. ThanksINSERT INTO ProjectEvent ( ProjectID, EventID, LeadTime, EstimatedCompletionDate ) SELECT @ProjectID, CSPD.EventID, E1.LeadTime, ( SELECT DATEADD( d, -SUM( E2.LeadTime ), @CustomerShipDate ) FROM Event AS E2 WHERE E2.EventID <= E1.EventID ) AS EstimatedCompletionDate FROM CompanySeasonProductTemplate AS CSPD, Event AS E1 WHERE CSPD.EventID = E1.EventID AND CSPD.CompanyID = @CompanyID AND SeasonID Is Null AND ProductCategoryID Is Null ORDER BY EventOrder |
 |
|
|
|
|
|
|
|