Problem while using UNION

Database
SAP
Enthusiast

Problem while using UNION

Hi ,

I am unable to run such queries . It says "Executed as Single statement.  Failed [3654 : HY000] Corresponding select-list expressions are incompatible.

Elapsed time = 00:00:00.000

STATEMENT 1: Select Statement failed."

SELECT A.FIELD1,

A.FIELD2,

a.FIELD3

FROM VT_SIBHI1

UNION

SELECT NULL AS FIELD1,

NULL AS FIELD2

CASE WHEN B.FIELD3 = 1 THEN NULL ELSE FIELD3 AS FIELD3

FROM VT_SIBHI2 B

;

Please help me on this

3 REPLIES
SAP
Enthusiast

Re: Problem while using UNION

Got the answer guys !!! Its like we need to make the datatype match not the Name of the columns .

Re: Problem while using UNION

Hi, did u use CAST function to resolve the issue...please let me know...

cast('' as char(10))

Thanks

GA
New Member

Re: Problem while using UNION

Hi, I faced the same issue. Here is how I resolved it.

 

What was the root cause - data type mismatch

what solved it - Data type of all correcponding feilds in the union needs to match. - I used CAST function to do that. 

 

Example - SyntaxEditor Code Snippet

CAST('VIDEO' AS VARCHAR(50))  AS PRODUCT,