0

I need to create a view which will query a few specified tables and return a view table with one row. Table must be formed with column with table names and one row must be returned with values True/False depending on the table have rows or not.

For example, I have four tables:

Medication / Patient / User / Appointment

I need to check them tables if they have rows or not and return a view table with one row and columns like that.

Medication | Patient | User | Appointment
True       | False   | False| True
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mindaugas
  • 163
  • 1
  • 7
  • 16
  • This information is already in MS SQL system tables, why do you want to create another view? – Perception Nov 18 '12 at 13:25
  • See the accepted answer [here](http://stackoverflow.com/questions/1443704/query-to-list-number-of-records-in-each-table-in-a-database) for a query you can modify – Perception Nov 18 '12 at 13:37

1 Answers1

1

There are quite a few ways to do this, if it is just these 4 tables you can use this:

select
(select Case When (select COUNT(*) FROM Medication) > 0 then 'true' else 'false' end) as Medication,
(select Case When (select COUNT(*) FROM Patient) > 0 then 'true' else 'false' end) as Patient,
(select Case When (select COUNT(*) FROM Appointment) > 0 then 'true' else 'false' end) as Appointment
Blachshma
  • 17,097
  • 4
  • 58
  • 72