Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Help
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Query Help
Environment versions
SQL Server:
SQL Server 2000
Application:
Desktop
Miscellaneous
Thread ID:
01390637
Message ID:
01390637
Views:
114
Hoping someone can help me tweak this query. We have two tables, the meeting and the meetproc table, for each case there is 1 meeting record, and there is at least 1 meetproc record, but there could be multiple meetproc records. The primary meeproc record is the one with the lowest sysorder value. Typically they are sequential (1,2,3), but depending on edits that may have occurred, they may start with a number other than 1 such as (3,4,5).

The part I need help with is determining which is the primary, in the query below I've just got a place holder for it. Anybody have an idea how I can determine if it the primary (lowest sysorder) for that CaseID?

Thanks
Select meetproc.procID,coPerID,
         (Select description from dbo.coProc where dbo.coProc.ProcID=meetproc.ProcID) as Procdesc,
         Cast(0 as bit) as isPrimary,
         meetings.meetingnumber as CaseID,
	 meetproc.Sysorder
from dbo.meetings inner join
     dbo.meetproc on dbo.meetings.meetingnumber=dbo.meetproc.Meetingnumber
where meetings.deptID=@DeptID
and   meetings.iscompleted=1
and   meetings.begintime between @begintime and @EndTime
order by meetings.meetingnumber,sysorder
Sample result would be:
ProcID    coPerID      ProcDesc             isPrimary     CaseID       Sysorder
-------------------------------------------------------------------------------------------------------------
9434        1241       Peripharal Angio         1              165390         1
9461        1241       PTA Lower Extr          0              165390         2
9485        1241       Other Proc                 0              165390         3
Next
Reply
Map
View

Click here to load this message in the networking platform