Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Question
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Query Question
Miscellaneous
Thread ID:
01059688
Message ID:
01059688
Views:
49
The code below is from a stored procedure, my question is, in the subquery for roomname, is it looking through all the records in the meetings table? If so, how might be a better way to write that portion.

Thanks
SELECT  dbo.coper.lastname, 
	dbo.coper.firstname, 
	dbo.coper.coperid, 
  (SELECT Top 1 dbo.corooms.roomname 
           FROM  dbo.meetings with INNER JOIN 
                 dbo.meetproc with   ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN 
                 dbo.corooms with  ON dbo.meetings.roomid = dbo.corooms.roomid  
           where @ttStart  between meetings.begintime and meetings.endtime 
  	   and meetproc.coperid=coPer.coPerID and isblock=0 and iscancelled=0) as RoomName,

	isnull(dbo.coper.isResident,0) as isResident, 
	isnull(dbo.coper.isSuspended,0) as isSuspended,
	0 as Numcancelled,
	0 as NumSched,
	isnull((Select specdesc from dbo.coSpec with (nolock) where coSpec.specID=coPer.SpecID and coSpec.Isactive=1),' ') as specdesc
FROM    dbo.coper INNER JOIN
        dbo.coperdept ON dbo.coper.coperid = dbo.coperdept.coperid
where coPerDept.deptID=@tiDept
and coPer.isactive=1
and coPer.perTypeID=1
order by coper.lastname,coPer.firstname
Reply
Map
View

Click here to load this message in the networking platform