I’m writing a Transact-SQL query which involves several UNIONS where, where the datatype of the second column is an int. The datatype of the first column is a varchar.
Here’s an example of the issue I’m having. In the SQL below, the query won’t run because it won’t let me leave the second column blank for that last SELECT statement. I put a blank varchar there (‘ ‘) but it requires an int, so am I forced to put in a dummy value like 0?
SELECT product, price
FROM tableA
UNION ALL
SELECT '', SUM(price)
FROM tableB
UNION ALL
SELECT '', ''
FROM tableC
Why not select null and cast it to a number when really necessary?