select distinct #table1.monthyear,#table1.unfield,ISNULL(#table2.field,0) as field
from #table1 left outer join #table2 on #table1.monthyear=#table2.monthyear
Good Luck
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
Please try below query, modified by @yrb.yogi's query.
SELECT Filled.Year,Filled.Month,Filled.MonthYear,Filled.FiledDt,Filled.UnFiled,ISNULL(Unfilled.UnFiled,0) AS Filed
FROM
(
select a.Year,a.Month,
LEFT (DATENAME(Month, DATEADD(Month, a.Month - 1, 0)), 3) + '-' + RIGHT (a.Year, 2) AS MonthYear,
CAST(CAST(a.Year AS varchar(5)) + '/' + a.Month + '/1' AS DATE) AS FiledDt,
SUM(a.NoOfCount) AS UnFiled
from t_HistoryFilledAttachmentByMonthMainTask a
where a.MainCategory<>'' AND a.MainCategory IS NOT NULL
AND (CAST(CAST(Year AS varchar(5)) + '/' + Month + '/1' AS DATE) BETWEEN @FromDate and @ToDate)
GROUP BY a.Month, a.Year ORDER BY CAST(CAST(a.Year AS varchar(5)) + '/' + a.Month + '/1' AS DATE)
) AS Filled
LEFT JOIN
(
select b.Year,b.Month,
LEFT (DATENAME(Month, DATEADD(Month, b.Month - 1, 0)), 3) + '-' + RIGHT (b.Year, 2) AS MonthYear,
CAST(CAST(b.Year AS varchar(5)) + '/' + b.Month + '/1' AS DATE) AS UnfiledDt,
SUM(b.NoOfCount)AS UnFiled
from t_HistoryUnFilledAttachmentByMonth b where b.MainCategory='' or b.MainCategory IS NULL
AND (CAST(CAST(Year AS varchar(5)) + '/' + Month + '/1' AS DATE) BETWEEN @FromDate and @ToDate)
GROUP BY b.Month, b.Year ORDER BY CAST(CAST(b.Year AS varchar(5)) + '/' + b.Month + '/1' AS DATE)
) AS Unfilled ON Filled.Year=Unfilled.Year and Filled.Month=Unfilled.Month
Best Regards,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Narsa
Member
105 Points
254 Posts
Re: Join two results in to one
Dec 27, 2012 08:25 AM|LINK
Hi,
giving only one result like this ..
MonthYear FieldFilled FiledDt Filed UnFiled
Dec-12 0 2012-12-01 377 2003
Narsa Reddy
yrb.yogi
Star
14460 Points
2402 Posts
Re: Join two results in to one
Dec 27, 2012 08:33 AM|LINK
change in left join condition/column like
.Net All About
KiaranNafade
Member
134 Points
58 Posts
Re: Combine 2 tables ?
Dec 27, 2012 08:37 AM|LINK
Select Table_2.MY,isnull(Table_1.UF,0)as UF,Table_2.F from Table_2
Left join Table_1
on Table_2.MY=Table_1.MY;
vendan
Participant
856 Points
293 Posts
Re: Combine 2 tables ?
Dec 27, 2012 10:02 AM|LINK
Hi,
Try below query
Kalaivendan
Please Mark as Answer if this post helps you!
NadeemZee
Participant
942 Points
178 Posts
Re: Combine 2 tables ?
Dec 27, 2012 10:28 AM|LINK
Hi check thid one:
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
Chen Yu - MS...
All-Star
21584 Points
2493 Posts
Microsoft
Re: Join two results in to one
Dec 28, 2012 01:57 AM|LINK
Hi,
Please try below query, modified by @yrb.yogi's query.
SELECT Filled.Year,Filled.Month,Filled.MonthYear,Filled.FiledDt,Filled.UnFiled,ISNULL(Unfilled.UnFiled,0) AS Filed FROM ( select a.Year,a.Month, LEFT (DATENAME(Month, DATEADD(Month, a.Month - 1, 0)), 3) + '-' + RIGHT (a.Year, 2) AS MonthYear, CAST(CAST(a.Year AS varchar(5)) + '/' + a.Month + '/1' AS DATE) AS FiledDt, SUM(a.NoOfCount) AS UnFiled from t_HistoryFilledAttachmentByMonthMainTask a where a.MainCategory<>'' AND a.MainCategory IS NOT NULL AND (CAST(CAST(Year AS varchar(5)) + '/' + Month + '/1' AS DATE) BETWEEN @FromDate and @ToDate) GROUP BY a.Month, a.Year ORDER BY CAST(CAST(a.Year AS varchar(5)) + '/' + a.Month + '/1' AS DATE) ) AS Filled LEFT JOIN ( select b.Year,b.Month, LEFT (DATENAME(Month, DATEADD(Month, b.Month - 1, 0)), 3) + '-' + RIGHT (b.Year, 2) AS MonthYear, CAST(CAST(b.Year AS varchar(5)) + '/' + b.Month + '/1' AS DATE) AS UnfiledDt, SUM(b.NoOfCount)AS UnFiled from t_HistoryUnFilledAttachmentByMonth b where b.MainCategory='' or b.MainCategory IS NULL AND (CAST(CAST(Year AS varchar(5)) + '/' + Month + '/1' AS DATE) BETWEEN @FromDate and @ToDate) GROUP BY b.Month, b.Year ORDER BY CAST(CAST(b.Year AS varchar(5)) + '/' + b.Month + '/1' AS DATE) ) AS Unfilled ON Filled.Year=Unfilled.Year and Filled.Month=Unfilled.MonthBest Regards,
Feedback to us
Develop and promote your apps in Windows Store