Hi all
I am not getting required result from a query left outer join on 3 table.
let me describe what are tables -
I have three tables
1. Months (that contain twelve rows for twelve months)
2. Montly_Data (contains user's monthly contributions(1 row for each month))
3. Master table (contain user's Master details, father name, dob etc..)
what i need to retrive is all user's contributions rows month wise(there should 12 rows for each user even there is no row in data table.) there is condition - particular financial-year and company's users should be included in result.
i have written following query -
SELECT ROUND(isnull(M.serial,0),0) [cnt],
isnull(M.monName,'') as [MONTHNM],
ISNULL(EPSbasic,0) [EPFBasic],
ISNULL(USERNAME,'') [USERNAME],
isnull(PFANO,'') [PFANO],
isnull(FatherName,'') [fathername],
isnull(dom,'') [DOM],
ISNULL(dol,'') [DOL],
isnull(pencont,0) [PenCont],
isnull(ROI,0) [ROI]
from EPF_MST_MONTH m left outer join EPF_USER_DATA d
ON M.cmonth=D.cmonth AND (D.finyear='2011-2012' and
D.empcode in ('FG0000658-D','FG0000664-D') AND D.CID='DEMO') or (d.empcode is null)
LEFT OUTER JOIN TDMS_MST_USERS U ON d.empcode = U.EmpCode
AND U.CID='DEMO' AND U.empcode in ('FG0000658-D','FG0000664-D')
Thanks in advance and any help on above issue is greately appreciated!