I have a stored proc which unions some data and returns back. At max that SP will return me 3 rows meeting the where condition.
Is there a way i can force the SP to return the blank row if there is no data present which matches the condition?
This is how my SP looks like:
SELECT Top 1 Col1, 'FirstResult' FROM Table T1
where SomeColumn='whatever'
UNION ALL
SELECT Top 1 Col2, 'SecondResult' FROM Table T1
where SomeColumn='whatever'
UNION ALL
SELECT Top 1 Col3, 'ThirdResult' FROM Table T1
where SomeColumn='whatever'
I want to always return me 3 rows regardless even if the condition doesnt match. Of course data will be empty or NULL in the resultset.
You can go here to demonstrate that the query in this answer works with no rows: http://www.sqlfiddle.com/#!3/51d1c/3
With 1 row in YourTable: http://www.sqlfiddle.com/#!3/ad1e8/1
Here is a procedure that should return what you are looking for: