Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create record number by group without grouping
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
How to create record number by group without grouping
Miscellaneous
Thread ID:
00886393
Message ID:
00886393
Views:
57
I don't know if this is possible, but I have a stored procedure that brings back some data, it's ordered by Date and room, but is not grouped. I'd like to create a column in the return set that numbered each record within a date and room.

Example:

1 02/03/2004 RM1 SMITH, MARY
2 02/03/2004 RM1 SMITH, JACK
1 02/03/2004 RM2 THOMAS, THETRAIN
2 02/03/2004 RM2 OTHER, PATIENT
3 02/03/2004 RM2 SOMEONE, OTHER


The query is below that i'm currently useing, thanks for any help.

Kirk
SELECT  dbo.meetings.meetingnumber,
	convert(varchar(12),dbo.meetings.Begintime,101) as CaseDate,
	dbo.patients.mpinumber,
	RTRIM(dbo.patients.lastname) + ', ' + RTRIM(dbo.patients.firstname) AS PatientName, 
	(SELECT  top 1 RTRIM(dbo.coper.lastname) + ', ' + RTRIM(dbo.coper.firstname) AS surgeonName
	   FROM dbo.meetings m INNER JOIN
                dbo.meetproc ON m.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN
                dbo.coper ON dbo.meetproc.coperid = dbo.coper.coperid
                where m.meetingnumber=meetings.meetingnumber
                order by meetproc.sysorder) as PrimarySurgeon,
	(SELECT  top 1 Description 
	   FROM dbo.meetings m INNER JOIN
                dbo.meetproc ON m.meetingnumber = dbo.meetproc.meetingnumber
                where m.meetingnumber=meetings.meetingnumber
                order by meetproc.sysorder) as PrimaryProcedure,

	dbo.corooms.roomname, 
	dbo.meetings.begintime as ScheduledStart, 
        dbo.meetings.enteror, 
	dbo.meetings.exitor, 
	dbo.meetings.surgeoninroom, 
	dbo.meetings.surgeonoutroom, 
	dbo.meetings.procstart, 
        dbo.meetings.procend,
	dbo.coRooms.DeptDisplayOrder,
	dbo.coRooms.SchedFrom as RoomOpens,
	dbo.coRooms.SchedTo   as RoomClosed,
	datediff(mi,enteror,exitor) as WheelsTimeUsedMins,
        datediff(mi,BeginTime,ProcStart) as CaseDelayMins,
	0 as turnMinutes,
	' ' as RoomOpensChar,
	' ' as RoomCloseChar
FROM    dbo.meetings INNER JOIN
        dbo.patients ON dbo.meetings.patientid = dbo.patients.patientid INNER JOIN
        dbo.corooms ON dbo.meetings.roomid = dbo.corooms.roomid
where iscompleted=1
Next
Reply
Map
View

Click here to load this message in the networking platform