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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Assigning times in SQL with allowances for breaks

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-05-03 : 10:42:06
Grant writes "Assume you have an assembly process that builds a "job" every "x" seconds. You have the following two basic tables to work with:

Table: JOBS Table: SCHEDULE
Key : JOB Key : PROD_START

JOB COLOR PROD_START PROD_STOP
--- ----- -------------------- -------------------
100 RED 2004-04-26 08:00:00 2004-04-26 12:00:00
101 RED 2004-04-26 12:30:00 2004-04-26 16:00:00
102 BLUE 2004-04-27 08:00:00 2004-04-27 12:00:00
103 RED 2004-04-27 12:30:00 2004-04-27 16:00:00

Given any job and a time it would be easy to determine at what time the following jobs would be built.

My question is how can you determine the time a job will be built it you must also take into account the start and stop times?

For example, if the build time was 5 minutes, or 300 seconds, and job 100 was built at 11:52, I would want to get back the following in a table:


JOB COLOR BUILD_TIME
--- ----- -------------------
100 RED 2004-04-26 11:52:00
101 RED 2004-04-26 11:57:00
102 BLUE 2004-04-26 12:32:00
103 RED 2004-04-26 12:37:00

Notice the long time between jobs 101 and 102. This caused by the break in the production schedule. In real life this would probably be a lunch break. However, job 102 still took 5 minutes to build when you take into account the 30 minute break.

Ideally this would all be done in a single, probably rather complicated, select statement. The next option would be a stored procedure.

What I need to decide is would it be better to do this on the server side or should I just send all the jobs back to the client and deal with it there in a higher level language?

This would be running on a Windows2000 Server with SQL2000 and all the latest service packs."

nr
SQLTeam MVY

12543 Posts

Posted - 2004-05-03 : 12:09:58
Depends. It will probably be faster in sql but you may be more comfortable with other languages.
Something like

update tbl
set BUILD_TIME = dateadd(mi,5*num,'20040426 10:47:00')
from tbl
join (select Job, (select num = count(*) from tbl t2 where t2.job <= t1.job) from tbl t2) a
on tbl.job = a.job

update tbl
set BUILD_TIME = dateadd(mi,30,BUILD_TIME)
where BUILD_TIME >= '20040426 12:00:00'


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -