Ian
Ian

Reputation: 35

number of rows in a stored procedure

is it possible to do conditional select based on a number of rows in a stored procedure?

E.g. if select * from table1 has no records, then do select * from table2?

Upvotes: 1

Views: 512

Answers (1)

Mark Byers
Mark Byers

Reputation: 838696

Try this:

SELECT col1, col2, ..., coln FROM table1
UNION ALL
SELECT col1, col2, ..., coln FROM table2
WHERE NOT EXISTS (SELECT * FROM table1)

This of course assumes that both tables have exactly the same structure.

Upvotes: 2

Related Questions