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 |
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2005-04-04 : 14:05:40
|
| I could not come up with a way around it on this one.Background I pull from a master table that contains the whole year in half hour increments logged as shift 1,2,3 with holidays marked shift (0 = no production) and drop a two week period into a table.The supervisor then gets to lock out shifts,days or hours that the machine will not be crewed or available by changeing the shift to 0. The result is dropped into another table with only active times showing. This procidure applies the correct job number from the schedule into the half hour incrments in the table and tests for gaps (these require the machine to be prepped again and add more time). The min and max give the job start time and stop time. If someone has a better Idea I would love to hear it as this will create quite a load when done for all machines in the plant.---------------------------------------------- Import active shifts SELECT IDENTITY (int, 1, 1) AS Shid , CAst(CalID AS int) AS CalID, CLdate, Shift, Schday, Workdate, Job_number_linkINTO dbo.[#Cal5C]FROM dbo.Cal5CWHERE (Shift > 0)Declare @shid int ,@stepcount int,@maxShid int,@startCalID int,@StopCalID intSelect @shid = 1 Select @stepcount =1 Select @maxShid = Max(shid) from #Cal5CWhile @shid < @maxShidBegin Select @Job_number_link = Job_number_link, @Timeblock = TimeblockFrom #TempSch Where stepcount = @stepcountSelect @startCalID = CalID From #Cal5C Where Shid = @shid------------------------------------------Check for break in shiftSelect @StopCalID = CalID From #Cal5CWhere Shid = @shid + (@Timeblock -1)If (@StopCalID - (@Timeblock -1)) > @startCalIDbeginSelect @Timeblock = @Timeblock + 3end-------------------------------------Update #Cal5CSet Job_number_link = @Job_number_linkWhere Shid between @shid and @shid + (@Timeblock -1)Update dbo.Cal5CSet Job_number_link = dbo.#cal5c.Job_number_linkFrom dbo.Cal5C inner join dbo.#cal5c on dbo.Cal5C.CalID = dbo.#Cal5C.CalIDselect @stepcount = @stepcount + 1Select @Shid = @shid + @TimeblockendSELECT dbo.Job_Number_Master_List.job_priority_number, dbo.Job_Number_Master_List.job_due_date, dbo.Job_Number_Master_List.job_number, dbo.Job_Number_Master_List.job_name, MIN(dbo.Cal5C.CLdate) AS Starttime, DATEADD(mi, 30, MAX(dbo.Cal5C.CLdate)) AS EndtimeFROM dbo.Job_Number_Master_List INNER JOIN dbo.Cal5C ON dbo.Job_Number_Master_List.Job_Number_Link = dbo.Cal5C.Job_number_linkGROUP BY dbo.Job_Number_Master_List.job_priority_number, dbo.Job_Number_Master_List.job_due_date, dbo.Job_Number_Master_List.job_number, dbo.Job_Number_Master_List.job_nameORDER BY MIN(dbo.Cal5C.CLdate) |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-04 : 14:39:09
|
can you provide some sample data, dml and ddl?Go with the flow & have fun! Else fight the flow |
 |
|
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2005-04-04 : 15:29:05
|
| Bit Long for the samples so we will link.ftp://calumetcarton.com/Autoschedule.docI only did 6 jobs. There are currently 66 for this machine alone.JimUsers <> Logic |
 |
|
|
|
|
|
|
|