Hi all,
I currently have a view in my database that pulls certain data from a table. The issue I run into is sometimes this table can be empty, and so I have an empty view.
I have been unsuccessful at using an IF statement inside of my view. Is it possible to have a statement such as this for the creation of my view...

if (select count(column) from table) > 0
select (column) from table
else
select (column) from table2

Have you considered puting this code in a stored procedure instead of a view? This type of code is easily implemented in a stored procedure.

If you require a view, then you may want to create a stored procedure to populate a separate table. This table can be populated according to the logic you describe. You would then view the populated table with a view.

If what I describe is acceptable for your needs and you need more information I can provide.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.