I have a query which gives me desired result. Column names are like this(which I am getting from the query):
RXID |DrName |SBOID |SBOName |RxHonoredDate |RxnHonoured |CallRecievedFrom |MobileNo
Now I have one table named 'SampleRepeat'. This have following columns
DrID | CallRecievedFrom | Mobile | SBOID |RxnHonoured
(Here we'll fetch DrName through DrID from table TblDr and SBOName through SBOID)
This is my query:
select G.RXID, NoOfRx, DrName,HospitalName,G.EmpCode AS SBOID ,TM_Name AS SBOName,CONVERT(DATETIME,H.CreatedDate) AS RxHonoredDate, DrSpeciality AS Speciality,
convert(DATETIME, G.CreatedDate) AS [RxGeneratedDate],COALESCE(H.rows, 0) AS RxnHonoured,
CallRecievedFrom,MobileNo ,G.HQ
from(
select RXID,SUM(RxGenerate) as NoOfRx, DrName,HospitalName,RX.EmpCode,TE.TM_Name, DrSpeciality,convert(DATE,RX.CreatedDate)as CreatedDate,TE.Territory AS HQ
from tbl_rx RX
left join tblEmployee TE on TE.TM_Emp_Id=RX.EmpCode
GROUP BY RX.EmpCode,RX.DrName,RX.HospitalName,RX.CreatedDate,RX.DrSpeciality,TE.TM_Name,RX.RXID,TE.Territory
)G
left join
( SELECT EmpCode,DrID,CreatedDate, SUM(MedToPCount) AS rows,CallRecievedFrom,MobileNo FROM tbl_MedicinToPatient WHERE Status = 'Delivered' GROUP BY EmpCode,DrID,CreatedDate,CallRecievedFrom,MobileNo
)H
on H.DrID=G.RXID ORDER BY TM_Name, H.CreatedDate ASC
I want to append this table values to end of query result and all other columns will be null.
I have tried Union all but no success. How do I do that? Any help would be much appreciated.
UNION ALLis indeed what you need. "No success" is a poor problem description, we need to see what you tried and in what way it failed.All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.