If in a stored procedure you can use If...Else :
IF (SELECT COUNT(*) FROM users) < 2 BEGIN SELECT age, name FROM users END ELSE SELECT age, name FROM users UNION ALL SELECT 25 AS age, 'Betty' AS name
Otherwise, you can try something like this:
SELECT age, name FROM users UNION ALL SELECT TOP 1 25 AS age, 'Betty' AS name FROM users WHERE (SELECT COUNT(*) FROM users) >= 2
Please note that I used UNION ALL , since it does not seem like you want to remove duplicates.
It is played here: http://sqlfiddle.com/#!6/a7540/2323/0
Change Instead of my second approach, I prefer Zohar . Therefore, if you can use If....Else , you would prefer that otherwise WHERE (SELECT COUNT(*) FROM users) > 1 without a table.
source share