Hi ,
i got one requirement like to write the recursive query. the same issue is resolved in oracle 10g with the help of connect by prior functionality.
here i am going to post my table structures with expected out put.
CREATE TABLE PROJWBS
(
wbs_id int,
parent_wbs_id int,
wbs_name varchar(100),
Proj_id int
)
INSERT INTO PROJWBS VALUES(1000,0,'A',1234)
INSERT INTO PROJWBS VALUES(1001,1000,'A.1',1234)
INSERT INTO PROJWBS VALUES(1002,1000,'B.1',1234)
CREATE TABLE TASK
(
task_id int,
task_code varchar(100),
Start_date1 datetime,
End_Date datetime,
wbs_id int
)
INSERT INTO TASK VALUES(10023,'A1010','01-12-2012','03-25-2013',1001)
INSERT INTO TASK VALUES(10025,'A1020','01-01-2012','03-10-2013',1001)
INSERT INTO TASK VALUES(10026,'B1200','09-08-2012','04-30-2013',1002)
INSERT INTO TASK VALUES(10027,'B1201','01-12-2012','01-01-2013',1002)
select * from projwb
select * from task
my expected output is:
wbs_idwbs_anme start_date End_Date
1000 A 1-Jan-12 30-Apr-13
1001 A.1 1-Jan-12 25-Mar-13
1002 B.1 8-Sep-12 30-Apr-13
i achieved the same output with the below query in oracle 10g? (i am new to sqlserver)
select wbsid, parent_wbsid, wbs_name ,
(
select min(start_date)
from task where wbsid in(
select wbsid
from projwbs
connect by prior wbsid=parent_wbsid start with parent_wbsid=a.wbsid)
or wbsid=a.wbsid
) start_dt,
(
select max(end_date)
from task where wbsid in(
select wbsid
from projwbs
connect by prior wbsid=parent_wbsid start with parent_wbsid=a.wbsid)
or wbsid=a.wbsid
) end_dt
please provide the solution.
thanks in advance