Problem with a VIEW
Posted in 1997
Hi all,
I'm with Florida's Agency for Health Care Administration. We run
Informix 7.21 on Solaris 2.5.1
I've run into an issue with view that I created to give name, mailing
address , street address, and bed count for hospitals on a regulatory
and admin licensing system. The view contains three outer joins, one
for each address type and one for the bed count. I've done the outers
because not every hospital has an address or bed count entered in the
system and I wanted the view to show all hospitals on the system.
The problem I'm experiencing is that I cannot join other tables to the
view nor can I do an order by or group by with a simple select from the
view. The error message I get is "A subquery returned not exactly one
row."
It appears the only use I can get from the view is from a simple select
(works fine). Can anyone who has had similar experiences please advise
on a solution or work-around. The SQL for the view follows:
create view facility_directory as
select lic.lic_id lic_id, -- license number (system)
lic.pro_cde pro_cde, -- hospital type
lic.lic_nbr license_nbr, -- license number (user)
name.nme name, -- hospital name
saddr.addr_line1 saddr1, -- street address
saddr.addr_line2 saddr2,
saddr.addr_cty scity,
saddr.addr_st sstate,
saddr.addr_zip szip,
saddr.phne_area sphone_area,
saddr.phne_nbr sphone_nbr,
maddr.addr_line1 maddr1, -- mailing address
maddr.addr_line2 maddr2,
maddr.addr_cty mcity,
maddr.addr_st mstate,
maddr.addr_zip mzip,
psd_val beds, -- bed count
lic.lic_sta_cde lic_status, -- Active/Inactive license
lic.rank_cde rank_cde -- a type code
from rbdlic lic, -- license table
rbdlhn name, -- Name table
outer rbdlad saddr, -- address table
outer rbdlad maddr,
outer rbdlpd psd -- table containing bed count
where lic.pro_cde = name.pro_cde
and lic.pro_cde = saddr.pro_cde
and lic.pro_cde = maddr.pro_cde
and lic.pro_cde = psd.pro_cde
and lic.lic_id = name.lic_id
and lic.lic_id = psd.lic_id
and saddr.addr_nbr = (select addr_nbr
from rbdlar a
where a.pro_cde = lic.pro_cde
and a.lic_id = lic.lic_id
and cur_addr_ind = "Y" -- current address
and lic_addr_typ_cde = "ST") -- Streetaddress
and maddr.addr_nbr = (select addr_nbr
from rbdlar a
where a.pro_cde = lic.pro_cde
and a.lic_id = lic.lic_id
and cur_addr_ind = "Y"
and lic_addr_typ_cde = "ML")
and name.cur_nme_ind = "Y"
and psd.psd_id = "CAPACITY";
A combination of lic_id and pro_cde will uniquely identify a record in
the license table.
Thanks in advance for any assistance/suggestions.
Yours,
James May,
Sr. DBA,
Agency for Health Care Administration, Florida