2

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?

user2888246
  • 175
  • 1
  • 4
  • 9

1 Answers1

8

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(..))

dnoeth
  • 59,503
  • 4
  • 39
  • 56
  • 1
    Also, I think it would be a good idea to explicitly CAST your character constant `opt' that you are creating in the first expression (perhaps CHAR(3) in this case) and use the same data type when you assign the null value. That will make what you are doing more obvious to you if you need to revise the code. – BellevueBob Oct 27 '13 at 14:31