Hi ShambhuRai
I hope try to bring an answer with this code. For your information, your screen of expected output hasn't same values as your script to create tables for the test.
select
b.min_start_date,
b.max_start_date,
DATEDIFF(DAY, max_start_date, min_start_date) as [4-5],
0 as [5-6]
from
(
select
(
select
min(testdata.PrdStartDate) as min_start_date
from
SKARABEE.dbo.testdata
where
testdata.prodstatus = 4
) as min_start_date,
(
select
max(testdata.PrdStartDate) as min_start_date
from
SKARABEE.dbo.testdata
where
testdata.prodstatus = 5
) as max_start_date
) as B
union
select
b.min_start_date,
b.max_start_date,
0 as [4-5],
DATEDIFF(DAY, max_start_date, min_start_date) as [5-6]
from
(
select
(
select
min(testdata.PrdStartDate) as min_start_date
from
SKARABEE.dbo.testdata
where
testdata.prodstatus = 5
) as min_start_date,
(
select
max(testdata.PrdStartDate) as min_start_date
from
SKARABEE.dbo.testdata
where
testdata.prodstatus = 6
) as max_start_date
) as B
Best Regards