I have a union all
that combines two statements for an SSRS report. I would like to create a third column that is based on a where clause from the table as the third field (col1
, and col2
being the first two fields). Essentially I'm wanting this:
DECLARE @Parameter int = 0
SELECT col1,col2, 'here I would like to use the result of another select col3 WHERE some_condition FROM table 1'
FROM table 1
WHERE @Parameter int = 0
UNION ALL
SELECT col1,col2, 'same as above'
FROM table 1
WHERE @Parameter int = 1
Best Answer
You could try subqueries
However, a subquery that returns more than one value will fail
This works but you have to consider that it can only return one value, and it could break easily
Result:
5 will be returned for each col1 and col2 value, because parameter = 0.
This fails