user2888246
user2888246

Reputation: 185

sql union all data type error with nulls

I have two tables which I have a 'union all' between.

My issue, I get a data mismatch error cause, in Table one I have select ... ,'opt' as opt from... Then in the second table I have select ..., null as opt from...

I know that I could have an empty string with '' as opt however, I don't want an empty string, I really do need it to be null. Is there anyway I can get the query to accept the null?

Upvotes: 2

Views: 7357

Answers (1)

dnoeth
dnoeth

Reputation: 60462

The parser internally assigns a datatype to a NULL and it's an INTEGER. Your column is not numeric thus resulting in s a type mismatch.

To solve this simply CAST(NULL AS VARCHAR(..))

Upvotes: 8

Related Questions