0
votes

I am trying to union 2 tables, one of table has required column type as 'Int' and another table has column type as 'uniqueidentifier'.. because of this when I try to do union of 2 tables I get this error:

Operand type clash uniqueidentifier is incompatible with int

Is there any way I can overcome this issue?

1
There might be the ways to overcome the situation but why you need that? How they can be the same in the join? - Prashant Pimpale
Each column of the result is strongly typed. Since one cannot convert int to uniqueidentifier and visa-versa, you could cast those columns to varchar in each query so they can be unioned. - Dan Guzman

1 Answers

1
votes

You could skip both column from column list or add NULL:

SELECT col1, col2, col3, col_GUID, NULL as col_INT FROM tab1
UNION ALL
SELECT col1, col2, col3, NULL AS col_GUID, col_INT FROM tab2