Using SQL Server 2008.
Here is a simplified example of my problem:
WITH cte ( a )
AS ( SELECT 1
UNION ALL
SELECT NULL
)
SELECT * INTO a_tmp FROM cte
SELECT * FROM a_tmp
This creates the table called a_tmp with a nullable int column.
The next snippet, however creates the table with a non-nullable column:
WITH cte ( a )
AS ( SELECT 1
UNION ALL
SELECT 2
)
SELECT * INTO a_tmp FROM cte
How can I change the second snippet to force the table to be created with all its columns nullable?
Make it into a computed expression as generally these get treated as
NULL-able unless wrapped inISNULL()