[英]SQL Server - error 'operand type clash uniqueidentifier is incompatible with int' with Union
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: 我正在尝试合并2个表,其中一个表的列类型要求为'Int',而另一个表的列类型为'uniqueidentifier'..因此,当我尝试进行2个表的合并时,出现此错误:
Operand type clash uniqueidentifier is incompatible with int
操作数类型冲突uniqueidentifier与int不兼容
Is there any way I can overcome this issue? 有什么办法可以解决这个问题?
You could skip both column from column list or add NULL
: 您可以从列列表中跳过两列,也可以添加
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.