Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
SELECT 
	1 AS STEP
	,'' AS ProviderName
	,'' AS Procedurecode
	,Claimid
	,Patient_First_Name
	,Patient_Last_Name
	,DOS
	,SUM(COALESCE(Total_Charge,0))
	,SUM(COALESCE(PaidAmount,0))
	,PostedDate
	,CheckEFTDate
	,CheckEFTNo 
FROM table_name 
GROUP BY ProviderName,Claimid,Patient_First_Name,Patient_Last_Name,DOS,PostedDate,CheckEFTDate,CheckEFTNo
UNION ALL
SELECT 
	2 AS STEP
	,'' AS ProviderName
	,'' AS Procedurecode
	,COUNT(Claimid)
	,'' AS Patient_First_Name
	,'' AS Patient_Last_Name
	,NULL::date AS DOS
	,SUM(COALESCE(Total_Charge,0))
	,SUM(COALESCE(PaidAmount,0))
	,NULL::date AS PostedDate
	,NULL::date AS CheckEFTDate
	,'' AS CheckEFTNo 
FROM table_name GROUP BY Claimid
Posted
Updated 20-Jul-15 5:55am
v2
Comments
[no name] 20-Jul-15 11:55am    
For UNION each field datatype Needs to match. Most probably this is not the case for "Claimid" vs. COUNT(Claimid). If the before (Claimid) is the case, you can work around by casting COUNT(Claimid) to CHAR(x) to match Clameid.

1 solution

As the error says, you have mismatching column types on both sides of the UNION. The column types between both queries must match.

So go through each column and compare them to each other. For example: Is ClaimId in query 1 same type as COUNT(Claimid) in query 2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900