Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help limiting This Query
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Help limiting This Query
Miscellaneous
Thread ID:
00852388
Message ID:
00852388
Views:
35
Once again, this query performs exactly as written....but i failed to properly understand a requirement. That is that when I select the data from meetings & meetproc, I only want the meetings that have only one child record in the meetproc table where the meetproc.procid=@tiProcID. Meetproc is a child table to meetings. Most the time, there is only one child record for each meeting record, BUT sometimes there are more. I want to exclude the ones that have more than one child record in meetproc, even if that meetproc record has the right @tiProcID.

Thanks for any help
select avg(det.ortime) as AvgORMinutes,
    (Select isnull(cleanup,0) from coProc where coProc.ProcID=det.procid) as Cleanup,
    (Select isnull(setup,0) from coProc where coProc.ProcID=det.procid) as Setup
	from (select top 20
 	        dbo.meetings.enteror, dbo.meetings.exitor,
	        datediff(mi,enteror,exitor) as ORTime,meetproc.procid
	      FROM dbo.meetings INNER JOIN
		   dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber
	      WHERE  (dbo.meetproc.coperid = @tiSurgeonID) AND (dbo.meetings.iscompleted = 1)
		  and  (dbo.meetproc.procid=@tiProcID)
  	     ORDER by endtime desc )det
group by det.procid
Next
Reply
Map
View

Click here to load this message in the networking platform