tags:

views:

100

answers:

1

Part of a complex query that our app is running contains the lines: ...(inner query)

SELECT
...
NULL as column_A,
NULL as column_B,
...
FROM
...

This syntax of creating columns with null values is not allowed in DB2 altough it is totally OK in MSSQL and Oracle DBs. Technically I can change it to:

'' as column_A,
'' as column_B, 

But this doesn't have exactly the same meaning and can damage our calculation results. How can I create columns with null values in DB2 using other syntax??

+3  A: 

DB2 is strongly typed, so you need to tell DB2 what kind of column your NULL is:

select 
   ...
   cast(NULL as int) as column_A,
   cast(NULL as varchar(128)) as column_B,
   ...
FROM
   ...
Ian Bjorhovde
This works in SQL Server as well. In SQL Server just using null without the cast gives you an int field.
HLGEM
it works - thanks!
Guy Roth