SQL Union causes "Conversion failed while converting varchar value to int"

I tried to find previous articles related to this, but I cannot find a specific situation. And since I'm new to stack overflow, I can't post photos, so I will try to describe it.

I have two datasets. One of them is 34 rows, 1 column of all NULLs. The remaining 13 rows, 1 varchars column.

When I try to combine all these two together, I get the message "Conversion failed while converting varchar value to int data type". I do not understand why I am getting this error. I have combined many null and varchar columns before, among many other types, and I am not getting this conversion error. Can anyone suggest suggestions why this error occurs?

+4
source share
1 answer

, , , - . - - , .

:

select t.*
from (select 'A' as col union all
      select 1
     ) t;

- SQL.

SQL Server union. , , . , .

EDIT:

NULL . NULL . , :

select NULL as col
union all
select 'A';

NULL, :

select cast(NULL as int) as col
union all
select 'A';

, SQL Server , , SQL Server NULL . , :

select (select NULL) as col
union all
select 'A';

, - .

+10

All Articles