Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help - Returning Customer with last x days
Message
General information
Forum:
Microsoft SQL Server
Category:
Replication
Miscellaneous
Thread ID:
00869960
Message ID:
00870166
Views:
15
I did get it to work, but I removed the:
WHERE patientID IN
clause did the following:
CREATE PROCEDURE ct_Get_ReturningCases
@QueryFrom DateTime,
@QueryTo DateTime,
@tiPastDays int

as

select *,
	(Select deptdesc from coDept where coDept.DeptID=det.prevDeptID) as PrevDept,
	(SELECT TOP 1 meetproc.description
	   FROM dbo.meetproc 
                where dbo.meetproc.meetingnumber=det.PrevMeetID
	   ORDER BY dbo.meetproc.sysorder) as PrevPrimaryProc,
	(Select RoomName from coRooms where coRooms.roomID=det.RoomID) as RoomName,
	(Select RoomName from coRooms where coRooms.roomID=det.PrevRoomID) as PrevRoomName
 
from
(select meetingnumber as Confnumber,begintime,EndTime,EnterOR,ExitOR,patientID,RoomID,
	(Select rtrim(Lastname)+', '+rtrim(FirstName) from patients where patientID=meetings.PatientID) as PatientName,
	(Select mpinumber from patients where patientID=meetings.PatientID) as medRecNo,
	(SELECT TOP 1 RTRIM(dbo.coper.lastname) + ', ' + RTRIM(dbo.coper.firstname)
	   FROM dbo.meetproc INNER JOIN
                dbo.coper ON dbo.meetproc.coperid = dbo.coper.coperid
                where dbo.meetproc.meetingnumber=meetings.meetingnumber
	   ORDER BY dbo.meetproc.sysorder) as SurgeonName,
	(SELECT TOP 1 meetproc.description
	   FROM dbo.meetproc 
                where dbo.meetproc.meetingnumber=meetings.meetingnumber
	   ORDER BY dbo.meetproc.sysorder) as PrimaryProc,
	(Select deptdesc from coDept where coDept.DeptID=meetings.DeptID) as DepartmentDesc,
	meetings.deptid,
	(Select top 1 m2.begintime from meetings m2 where m2.iscompleted=1 and m2.begintime < meetings.BeginTime and isblock=0and m2.patientID=meetings.patientID order by begintime desc) as PrevDate,
	(Select top 1 m2.deptID    from meetings m2 where m2.iscompleted=1 and m2.begintime < meetings.BeginTime and isblock=0and m2.patientID=meetings.patientID order by begintime desc) as PrevDeptID,
	(Select top 1 m2.meetingnumber from meetings m2 where m2.iscompleted=1 and m2.begintime < meetings.BeginTime and isblock=0 and m2.patientID=meetings.patientID order by begintime desc) as PrevMeetID,
	(Select top 1 datediff(dd,m2.begintime,meetings.begintime) from meetings m2 where m2.iscompleted=1 and m2.begintime < meetings.BeginTime and isblock=0 and m2.patientID=meetings.patientID order by begintime desc) as DaysPrev,
	(Select top 1 RoomID from meetings m2 where m2.iscompleted=1 and m2.begintime < meetings.BeginTime and isblock=0 and m2.patientID=meetings.patientID order by begintime desc) as PrevRoomID

from meetings
where begintime between @QueryFrom and @QueryTo
and iscompleted=1
and isblock=0) as det
where det.DaysPrev between 0 and @tiPastDays
order by Departmentdesc,patientname
Previous
Reply
Map
View

Click here to load this message in the networking platform