June 8, 2008 at 1:24 pm
Hi folks,
I have a database table named ProcessTest1. I would like to get the deadline dates of business processes. This table contains parametric values of the sequential business processes.The table structure is like below:
CREATE TABLE [dbo].[ProcessTest1](
[ProcessID] [char](4) ,
[ProcessName] [char](50) ,
[FabricType] [char](1) ,
[ProductType] [int] NULL,
[ProductStyle] [char](1) ,
[StockType] [int] NULL,
[ProductLine] [char](1) ,
[DayCount] [int] NULL,
[OverlappedTo] [char](4) ,
[OverlapDayCount] [int] NULL,
[ProcessAfter] [char](4)
) ON [PRIMARY]
------------
--------------------------------------
My sample data is like below:
INSERT INTO ProcessTest1 VALUES ('001','Process1','D',1,'T',2,'W',12,NULL,NULL,NULL)
INSERT INTO ProcessTest1 VALUES ('002','Process2','D',1,'T',2,'W',1,'001',1,'001')
INSERT INTO ProcessTest1 VALUES ('003','Process3','D',1,'T',2,'W',2,'001',2,'002')
INSERT INTO ProcessTest1 VALUES ('004','Process4','D',1,'T',2,'W',2,'001',2,'003')
INSERT INTO ProcessTest1 VALUES ('005','Process5','D',1,'T',2,'W',4,NULL,NULL,'001')
INSERT INTO ProcessTest1 VALUES ('006','Process6','D',1,'T',2,'W',4,NULL,NULL,'005')
-----------
Expected Result is:
'001', '21.06.2008' (Root Process)
'002','10.06.2008' (OverlappedTo root process)
'003','12.06.2008' (OverlappedTo root process and Sequential to previous process '002')
'004','14.06.2008' (OverlappedTo root process and Sequential to previous process '003')
'005','25.06.2008' (Sequential to previous process '001')
'006','29.06.2008' (sequential to previous process '005')
If I enter the current date and then how can I get the final deadline time by using this database table?
I mean, I would like to get a new resultset that contains 2 columns such as:
ProcessID and DeadLine
Please help..
June 8, 2008 at 10:43 pm
Where are you entering the Current date and also there is no deadLine COlumn in this table.
Are you trying to calculate the DeadLine based on the Given Current Date using some calculations. Can you give some Samole Datas and Expected Results
Rajesh
June 9, 2008 at 1:59 am
I should enter getdate() (or another date value) as an input parameter. The sub-process final dates will vary based on this input parameter.And there should be a recursion in this query.Right?
June 9, 2008 at 6:16 am
Oh God!!!
I really dont believe this..My message has been read more than 650 times and there is still no comment or solution :):):)
June 9, 2008 at 6:54 am
DECLARE@ProcessTest TABLE
(
ProcessID CHAR(3),
ProcessName VARCHAR(50),
FabricType CHAR(1),
ProductType INT,
ProductStyle CHAR(1),
StockType INT,
ProductLine CHAR(1),
DayCount INT,
OverlappedTo CHAR(3),
OverlapDayCount INT,
ProcessAfter CHAR(3)
)
INSERT@ProcessTest
SELECT'001', 'Process1', 'D', 1, 'T', 2, 'W', 12, NULL, NULL, NULL UNION ALL
SELECT'002', 'Process2', 'D', 1, 'T', 2, 'W', 1, '001', 1, '001' UNION ALL
SELECT'003', 'Process3', 'D', 1, 'T', 2, 'W', 2, '001', 2, '002' UNION ALL
SELECT'004', 'Process4', 'D', 1, 'T', 2, 'W', 2, '001', 2, '003' UNION ALL
SELECT'005', 'Process5', 'D', 1, 'T', 2, 'W', 4, NULL, NULL, '001' UNION ALL
SELECT'006', 'Process6', 'D', 1, 'T', 2, 'W', 4, NULL, NULL, '005'
/*
'001', '21.06.2008' (Root Process)
'002', '10.06.2008' (OverlappedTo root process)
'003', '12.06.2008' (OverlappedTo root process and Sequential to previous process '002')
'004', '14.06.2008' (OverlappedTo root process and Sequential to previous process '003')
'005', '25.06.2008' (Sequential to previous process '001')
'006', '29.06.2008' (sequential to previous process '005')
*/
; WITH Yak (ProcessID, theDate, thePath, dc)
AS (
SELECTProcessID,
DATEADD(DAY, DayCount + DATEDIFF(DAY, '19000101', GETDATE()), '19000101'),
'/' + CAST(ProcessID AS VARCHAR(MAX)) + '/',
DayCount
FROM@ProcessTest
WHEREProcessAfter IS NULL
UNION ALL
SELECTpt.ProcessID,
DATEADD(DAY, CASE
WHEN y.thePath = '/' + pt.OverlappedTo + '/' THEN pt.OverlapDayCount - y.dc
ELSE pt.DayCount
END, y.theDate),
y.thePath + CAST(pt.ProcessID AS VARCHAR(12)) + '/',
dc
FROM@ProcessTest AS pt
INNER JOINYak AS y ON y.ProcessID = pt.ProcessAfter
)
SELECTProcessID,
theDate
FROMYak
ORDER BYthePath
N 56°04'39.16"
E 12°55'05.25"
June 9, 2008 at 6:54 am
Heh... yeah... 648 of them were me trying to figure out your problem... 😉
I could make it 651 ya know... 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
June 9, 2008 at 6:59 am
Nicely done, Peter! I'm still kinda new to the 2005 world and I keep forgetting about stuff like that...
heh... especially on a 2k forum 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
June 9, 2008 at 7:08 am
I see that now.
I responded to a PM and saw that OP posted same question on the forums.
Didn't notice the version.
N 56°04'39.16"
E 12°55'05.25"
June 9, 2008 at 7:24 am
Oh god!!!!!
Where were you :):):)
Well, viewer count exceeded 700 🙂
Thank you very much for your replies (also thanks to all readers..:) ).If it possible I would like to ask another question based on this query.
How can I use a date parameter instead of GetDate() ?
June 9, 2008 at 7:30 am
ALTER PROCEDURE dbo.uspMyProcedure
(
@Today DATETIME = NULL
)
AS
SET NOCOUNT ON
IF @Today IS NULL
SET@Today = DATEDIFF(DAY, '19000101', GETDATE())
ELSE
SET@Today = DATEDIFF(DAY, '19000101', @Today)
;WITH Yak (ProcessID, theDate, thePath, dc)
AS (
SELECTProcessID,
DATEADD(DAY, DayCount, @Today),
'/' + CAST(ProcessID AS VARCHAR(MAX)) + '/',
DayCount
FROMProcessTest1
WHEREProcessAfter IS NULL
UNION ALL
SELECTpt.ProcessID,
DATEADD(DAY, CASE
WHEN y.thePath = '/' + pt.OverlappedTo + '/' THEN pt.OverlapDayCount - y.dc
ELSE pt.DayCount
END, y.theDate),
y.thePath + CAST(pt.ProcessID AS VARCHAR(12)) + '/',
y.dc
FROMProcessTest1 AS pt
INNER JOINYak AS y ON y.ProcessID = pt.ProcessAfter
)
SELECTProcessID,
theDate
FROMYak
ORDER BYthePath
N 56°04'39.16"
E 12°55'05.25"
June 9, 2008 at 7:39 am
Peso (6/9/2008)
I see that now.I responded to a PM and saw that OP posted same question on the forums.
Didn't notice the version.
Thanks for the feedback, Peter... Op seems happy with the excellent 2k5 solution. Too bad... was putting the final touches on the 2k solution but I'll quit now. I, too, was responding to a PM... guess I won't respond to those types of PM's anymore.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 9, 2008 at 7:42 am
It works like a ferrari... 🙂
Now I will try to extend this procedure by using "business days=working days" of a week..Is it possible to use working days of a week?
THANK YOU VERY MUCH......
June 9, 2008 at 7:49 am
I just clicked OP's "all post" to see if I didn't invent the wheel again.
If I hadn't, both you and me would present a working solution. What a waste of time.
N 56°04'39.16"
E 12°55'05.25"
June 9, 2008 at 7:53 am
Ok...You are exactly right..
Thanks again
June 9, 2008 at 7:59 am
Peso (6/9/2008)
I just clicked OP's "all post" to see if I didn't invent the wheel again.If I hadn't, both you and me would present a working solution. What a waste of time.
Yep, me too! I'm outa here... keep the shiney side up ol' friend.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply