i have two select statement from two different table and the common join field a datefield one date field name is JobFinishedDate and it is from MyJobs table and another date field name is createddate and it is from DailyFinishJobsHistory table
here is my two independent sql
sql 1
SELECT CONVERT(varchar,createddate,101) as [Date],
SUM([No of Jobs]) as [No of Jobs],
SUM([Turnaround Time]) as [Turnaround Time],
SUM([One Day Per]) as [One Day Per],
ROUND((SUM([No of Jobs]) * SUM([Turnaround Time])),2) as [TOTAL hours]
from DailyFinishJobsHistory d
WHERE CONVERT(varchar,createddate,112)>='20131015' AND CONVERT(varchar,createddate,112)<='20131021'
group by createddate
sql 2
Select
convert(varchar,JobFinishedDate,112) as JobFinishedDate
, Count(*) [Number of techs]
From
(
select
convert(varchar,JobFinishedDate,112) JobFinishedDate,Specialist
from MyJobs
where convert(varchar,JobFinishedDate,112)>='20131015'
and convert(varchar,JobFinishedDate,112) <='20131021'
and JobState='FINISHED'
group by convert(varchar,JobFinishedDate,112) , Specialist
) t1
Group By
JobFinishedDate
now i have to join. i tried like this way but right syntax is not coming to my mind to join this way.
SELECT CONVERT(varchar,createddate,101) as [Date],
SUM([No of Jobs]) as [No of Jobs],
SUM([Turnaround Time]) as [Turnaround Time],
SUM([One Day Per]) as [One Day Per],
ROUND((SUM([No of Jobs]) * SUM([Turnaround Time])),2) as [TOTAL hours],
(
Select
convert(varchar,JobFinishedDate,112) as JobFinishedDate
, Count(*) [Number of techs]
From
(
select
convert(varchar,JobFinishedDate,112) JobFinishedDate,Specialist
from bbajobs
where convert(varchar,JobFinishedDate,112)>='20131015'
and convert(varchar,JobFinishedDate,112) <='20131021'
and JobState='FINISHED'
group by convert(varchar,JobFinishedDate,112) , Specialist
) t1
Group By
JobFinishedDate
) a
from DailyFinishJobsHistory d
WHERE CONVERT(varchar,createddate,112)>='20131015' AND CONVERT(varchar,createddate,112)<='20131021'
group by createddate
so please help me bit to build the join. thanks
EDIT
i tried this script also but [Number of techs] is getting NULL
SELECT CONVERT(varchar,createddate,101) as [Date],
SUM([No of Jobs]) as [No of Jobs],
SUM([Turnaround Time]) as [Turnaround Time],
SUM([One Day Per]) as [One Day Per],
ROUND((SUM([No of Jobs]) * SUM([Turnaround Time])),2) as [TOTAL hours],
(
SELECT
--CONVERT(varchar,JobFinishedDate,112) as JobFinishedDate,
COUNT(*) [Number of techs]
From
(
SELECT CONVERT(varchar,JobFinishedDate,112) JobFinishedDate,
Specialist
FROM bbajobs
WHERE d.createddate=JobFinishedDate AND
JobState = 'FINISHED'
GROUP BY CONVERT(varchar,JobFinishedDate,112), Specialist
) t1
GROUP BY JobFinishedDate
) [Number of techs]
FROM DailyFinishJobsHistory d
WHERE CONVERT(varchar,createddate,112) >= '20131015' AND CONVERT(varchar,createddate,112) <= '20131021'
GROUP BY createddate