4

Query 1:

SELECT COUNT (A.EMPNO) AS [PRESENT]    
FROM ERPDATA.NIITESS.DBO.ZEMP_MASXST_WEB_AL A INNER                    
JOIN PPA_EVENTWISEEMPLOYEEMASTER B ON 
(CASE B.VC_BA WHEN '%' THEN LTRIM(RTRIM(A.PDIBUSHORT)) ELSE B.VC_BA END) =  LTRIM(RTRIM(A.PDIBUSHORT))                   
AND (CASE B.VC_PA WHEN '%' THEN A.PA ELSE B.VC_PA END) = A.PA                
WHERE A.STATUS = 3  
AND A.EMPNO IN (SELECT VC_EMPCODE FROM ERPDATA.NIITESS.DBO.ADA_MXEASTER WHERE IN_ATTENDANCE_STATUS = 1 AND CH_ACTIVE = 'Y' AND VC_EMPCODE <> '')                    
GROUP BY B.IN_EVENTID

Query 2:

SELECT COUNT (A.EMPNO) AS [TOTAL]    
FROM ERPDATA.NIITESS.DBO.ZEMP_MASXST_WEB_AL A INNER                    
JOIN PPA_EVENTWISEEMPLOYEEMASTER B ON 
(CASE B.VC_BA WHEN '%' THEN LTRIM(RTRIM(A.PDIBUSHORT)) ELSE B.VC_BA END) =  LTRIM(RTRIM(A.PDIBUSHORT))                   
AND (CASE B.VC_PA WHEN '%' THEN A.PA ELSE B.VC_PA END) = A.PA                
WHERE A.STATUS = 3  

I want to merge the two results into two columns with an absent column = query 2 - query 1 to process speed faster. How can i do it? EXAMPLE :
I HAVE TWO RESULT :
//----------------------------------------QUERY : 1
1
2
3
4
//-------------------------------------- QUERY : 2
4
5
6
8

//------------------------------------OUTCOME AS in two columns
1   5
2   6
3   7
4   8

1
  • What will be the matching condition for your result. Your outcome can also be i.e. (1,8), (2,5), (3, 6), (4,7) or any other combination. There is no condition based on which querys will be joined. Commented Nov 27, 2012 at 7:35

1 Answer 1

5
Select a.C1-b.C2 as Res
 from
(
Select Count(*) as C1 from Users
Group by Name
) a
join
(
Select Count(*) as C2 from User2
Group by Name
) b ON 1=1 -- or desired condition if existing
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.