NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

DECLARE @SwapTABLE TABLE(rESOID BIGINT)
INSERT INTO @SwapTABLE
select B.ResourceOID from
CPMBooking A
inner join
CPMBooking B
on A.CPMScheduleOID = B.CPMScheduleOID
and A.ResourceOID = B.ResourceOID
and A.CPMEntityOID <> B.CPMEntityOID
inner join PatientAppointmentIP PAT1
on A.OID = PAT1.CPMBookingOID
and A.ResourceOID = PAT1.PatientOID
inner join PatientAppointmentIP PAT2
on B.OID = PAT2.CPMBookingOID
and B.ResourceOID = PAT2.PatientOID
left outer join CPMBookingStatus CPMBkStsChildBKOID
on CPMBkStsChildBKOID.ChildCPMBookingOID = B.OID
where
A.APPSTCode = 'CC_TRANSFERRED'
and B.APPSTCode = 'CC_ADMITTED'
and A.EndDTTM = B.StartDTTM
and A.Status = 'A'
and B.Status = 'A'
and CPMBkStsChildBKOID.OID is null
and PAT1.Status = 'A'
and PAT2.Status = 'A'
;with CTE(Resourceoid1,resourceoid2)
as
(
select A.ResourceOID,B.ResourceOID from (select b1.APPSTCode SrcAPPSTCode, b2.APPSTCode TrgAPPSTCode, b1.CPMScheduleOID,b1.ResourceOID,
b1.OID SrcBookOID,b1.StartDTTM SrcBookStart, b1.EndDTTM SrcEnd, b1.CPMEntityOID SrcEntityOID,
PAT1.OID SrcPATAppOID,PAT1.StartDTTM SrcPATAppStart,PAT1.EndDTTM SrcPATAppEnd,PAT1.EncounterOID SrcEncounterOID,PAT1.PrefBDCATCode SrcBedCategory, PAT1.APPSTCode SrcPATAppStatus,
b2.OID TrgBookOID,b2.StartDTTM TrgStart, b2.EndDTTM TrgEnd, b2.CPMEntityOID TrgEntityOID,
PAT2.OID TrgPATAppOID,PAT2.StartDTTM TrgPATAppStart,PAT2.EndDTTM TrgPATAppEnd,PAT2.EncounterOID TrgEncounterOID,PAT2.PrefBDCATCode TrgBedCategory, PAT2.APPSTCode TrgPATAppStatus
,ROW_NUMBER() over (Partition BY
b1.CPMScheduleOID,b1.EndDTTM,b2.startdttm order by
b1.StartDTTM DESC) id,CPMBkStsChildBKOID.OID
from
cpmbooking b1
inner join
CPMBooking b2
on b1.CPMScheduleOID=b2.CPMScheduleOID
and b1.ResourceOID = b2.ResourceOID
and b1.EndDTTM = b2.StartDTTM
and b1.CPMEntityOID <> b2.CPMEntityOID
and b1.EndDTTM = b2.StartDTTM
inner join PatientAppointmentIP PAT1
on b1.OID = PAT1.CPMBookingOID
and b1.ResourceOID = PAT1.PatientOID
inner join PatientAppointmentIP PAT2
on b2.OID = PAT2.CPMBookingOID
and b2.ResourceOID = PAT2.PatientOID
left outer join CPMBookingStatus CPMBkStsChildBKOID
on CPMBkStsChildBKOID.ChildCPMBookingOID = b2.OID
where
b1.APPSTCode = 'CC_TRANSFERRED'
and b2.APPSTCode = 'CC_ADMITTED'
and CPMBkStsChildBKOID.OID is null
and b1.Status = 'A'
and b2.Status = 'A'
and PAT1.Status = 'A'
and PAT2.Status = 'A') A
inner join
(select b1.APPSTCode SrcAPPSTCode, b2.APPSTCode TrgAPPSTCode, b1.CPMScheduleOID,b1.ResourceOID,
b1.OID SrcBookOID,b1.StartDTTM SrcBookStart, b1.EndDTTM SrcEnd, b1.CPMEntityOID SrcEntityOID,
PAT1.OID SrcPATAppOID,PAT1.StartDTTM SrcPATAppStart,PAT1.EndDTTM SrcPATAppEnd,PAT1.EncounterOID SrcEncounterOID,PAT1.PrefBDCATCode SrcBedCategory, PAT1.APPSTCode SrcPATAppStatus,
b2.OID TrgBookOID,b2.StartDTTM TrgStart, b2.EndDTTM TrgEnd, b2.CPMEntityOID TrgEntityOID,
PAT2.OID TrgPATAppOID,PAT2.StartDTTM TrgPATAppStart,PAT2.EndDTTM TrgPATAppEnd,PAT2.EncounterOID TrgEncounterOID,PAT2.PrefBDCATCode TrgBedCategory, PAT2.APPSTCode TrgPATAppStatus
,ROW_NUMBER() over (Partition BY
b1.CPMScheduleOID,b1.EndDTTM,b2.startdttm order by
b1.StartDTTM DESC) id,CPMBkStsChildBKOID.OID
from cpmbooking b1 inner join CPMBooking b2
on b1.CPMScheduleOID=b2.CPMScheduleOID
and b1.ResourceOID = b2.ResourceOID
and b1.EndDTTM = b2.StartDTTM
and b1.CPMEntityOID <> b2.CPMEntityOID
and b1.EndDTTM = b2.StartDTTM
inner join PatientAppointmentIP PAT1
on b1.OID = PAT1.CPMBookingOID
inner join PatientAppointmentIP PAT2
on b2.OID = PAT2.CPMBookingOID
left outer join CPMBookingStatus CPMBkStsChildBKOID
on CPMBkStsChildBKOID.ChildCPMBookingOID = b2.OID
where
b1.APPSTCode = 'CC_TRANSFERRED'
and b2.APPSTCode IN ('CC_ADMITTED','CC_BOOKED')
and CPMBkStsChildBKOID.OID is null
and b1.Status = 'A'
and b2.Status = 'A'
and PAT1.Status = 'A'
and PAT2.Status = 'A') B
on
A.CPMScheduleOID = B.CPMScheduleOID
and A.SrcEnd = B.SrcEnd
and A.TrgStart = B.TrgStart
and A.SrcEntityOID = B.TrgEntityOID
and A.TrgEntityOID = B.SrcEntityOID
where A.id=1
and B.id=2
union

select A.ResourceOID,B.ResourceOID from (select b1.APPSTCode SrcAPPSTCode, b2.APPSTCode TrgAPPSTCode, b1.CPMScheduleOID,b1.ResourceOID,
b1.OID SrcBookOID,b1.StartDTTM SrcBookStart, b1.EndDTTM SrcEnd, b1.CPMEntityOID SrcEntityOID,
PAT1.OID SrcPATAppOID,PAT1.StartDTTM SrcPATAppStart,PAT1.EndDTTM SrcPATAppEnd,PAT1.EncounterOID SrcEncounterOID,PAT1.PrefBDCATCode SrcBedCategory, PAT1.APPSTCode SrcPATAppStatus,
b2.OID TrgBookOID,b2.StartDTTM TrgStart, b2.EndDTTM TrgEnd, b2.CPMEntityOID TrgEntityOID,
PAT2.OID TrgPATAppOID,PAT2.StartDTTM TrgPATAppStart,PAT2.EndDTTM TrgPATAppEnd,PAT2.EncounterOID TrgEncounterOID,PAT2.PrefBDCATCode TrgBedCategory, PAT2.APPSTCode TrgPATAppStatus
,ROW_NUMBER() over (Partition BY
b1.CPMScheduleOID,b1.EndDTTM,b2.startdttm order by
b1.StartDTTM DESC) id,CPMBkStsChildBKOID.OID
from
cpmbooking b1
inner join
CPMBooking b2
on b1.CPMScheduleOID=b2.CPMScheduleOID
and b1.ResourceOID = b2.ResourceOID
and b1.EndDTTM = b2.StartDTTM
and b1.CPMEntityOID <> b2.CPMEntityOID
and b1.EndDTTM = b2.StartDTTM
inner join PatientAppointmentIP PAT1
on b1.OID = PAT1.CPMBookingOID
and b1.ResourceOID = PAT1.PatientOID
inner join PatientAppointmentIP PAT2
on b2.OID = PAT2.CPMBookingOID
and b2.ResourceOID = PAT2.PatientOID
left outer join CPMBookingStatus CPMBkStsChildBKOID
on CPMBkStsChildBKOID.ChildCPMBookingOID = b2.OID
where
b1.APPSTCode = 'CC_TRANSFERRED'
and b2.APPSTCode = 'CC_BOOKED'
and CPMBkStsChildBKOID.OID is null
and b1.Status = 'A'
and b2.Status = 'A'
and PAT1.Status = 'A'
and PAT2.Status = 'A') A
inner join
(select b1.APPSTCode SrcAPPSTCode, b2.APPSTCode TrgAPPSTCode, b1.CPMScheduleOID,b1.ResourceOID,
b1.OID SrcBookOID,b1.StartDTTM SrcBookStart, b1.EndDTTM SrcEnd, b1.CPMEntityOID SrcEntityOID,
PAT1.OID SrcPATAppOID,PAT1.StartDTTM SrcPATAppStart,PAT1.EndDTTM SrcPATAppEnd,PAT1.EncounterOID SrcEncounterOID,PAT1.PrefBDCATCode SrcBedCategory, PAT1.APPSTCode SrcPATAppStatus,
b2.OID TrgBookOID,b2.StartDTTM TrgStart, b2.EndDTTM TrgEnd, b2.CPMEntityOID TrgEntityOID,
PAT2.OID TrgPATAppOID,PAT2.StartDTTM TrgPATAppStart,PAT2.EndDTTM TrgPATAppEnd,PAT2.EncounterOID TrgEncounterOID,PAT2.PrefBDCATCode TrgBedCategory, PAT2.APPSTCode TrgPATAppStatus
,ROW_NUMBER() over (Partition BY
b1.CPMScheduleOID,b1.EndDTTM,b2.startdttm order by
b1.StartDTTM DESC) id,CPMBkStsChildBKOID.OID
from cpmbooking b1 inner join CPMBooking b2
on b1.CPMScheduleOID=b2.CPMScheduleOID
and b1.ResourceOID = b2.ResourceOID
and b1.EndDTTM = b2.StartDTTM
and b1.CPMEntityOID <> b2.CPMEntityOID
and b1.EndDTTM = b2.StartDTTM
inner join PatientAppointmentIP PAT1
on b1.OID = PAT1.CPMBookingOID
inner join PatientAppointmentIP PAT2
on b2.OID = PAT2.CPMBookingOID
left outer join CPMBookingStatus CPMBkStsChildBKOID
on CPMBkStsChildBKOID.ChildCPMBookingOID = b2.OID
where
b1.APPSTCode = 'CC_TRANSFERRED'
and b2.APPSTCode IN ('CC_ADMITTED')
and CPMBkStsChildBKOID.OID is null
and b1.Status = 'A'
and b2.Status = 'A'
and PAT1.Status = 'A'
and PAT2.Status = 'A') B
on
A.CPMScheduleOID = B.CPMScheduleOID
and A.SrcEnd = B.SrcEnd
and A.TrgStart = B.TrgStart
and A.SrcEntityOID = B.TrgEntityOID
and A.TrgEntityOID = B.SrcEntityOID
where A.id=1
and B.id=2
)

SELECT * FROM
@SwapTABLE T
LEFT OUTER JOIN
CTE
ON
T.rESOID = CTE.Resourceoid1 OR T.rESOID = CTE.resourceoid2
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.