I would like to combine the following 3 select statements:
1.
select SECTION_ENGLISH_DESC, D_REGULATION.REG_ENGLISH_DESC, D_SECTION.REG_SURR_ID from D_SECTION INNER JOIN D_REGULATION on D_SECTION.REG_SURR_ID = D_REGULATION.REG_SURR_ID where D_SECTION.reg_surr_id in ('101')
2.
Select count(*) from F_INSPECTIONS where REG_SURR_ID = '101'
3.
select CASE COUNT(*)
WHEN 0 THEN 'Compliant'
ELSE 'Not Compliant'
END
from F_VIOLATIONS
where SECTION_SURR_ID = '201'
the first statement is the main "frame" for what i want to get back. It should loop through all the inspections for 1 regulation (101).
the second statement, i know, is redundant but thats fine. (i get the same number of inspections for the same regulation for each inspection).
The third statement should return weather the current section is compliant (for reg 101). So that example would be for a single section (201) which may be included in reglation 201.
(a regulation has many sections)
Thanks a lot,
Dave Benoitplease don't cross-post
http://www.dbforums.com/showthread.php?t=1117027sql
Thursday, March 29, 2012
Correlated SUB Queries?
Labels:
combine,
correlated,
d_regulation,
d_section,
database,
following,
microsoft,
mysql,
oracle,
queries,
reg_english_desc,
reg_surr_id,
section_english_desc,
select,
server,
sql,
statements1,
sub
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment