Ali
Ali

Reputation: 25

i have start-time and End-time for a patient visit (in visit table). I want to assign a visit to user(hospital team member)

I have start-time and End-time for a patient visit (in visit table). I want to assign a Patient-visit to user(hospital team member). Can any one help me out for SQl query to find whither particular user is already assigned or not within that visit date(Start-time and End-Time)?

I just want a SQL function where i return 'Already Assigned' -or- 'free'

I have a table structure like this

appointment table=> AppointmentId int UserId nvarchar(128)
ClientVisitId int AppointmentDateTime datetime
StartTime datetime
EndTime datetime
Status int

ClientVisits table=> ClientVisitId int VisitDate datetime
ClientId int
StartTime datetime
EndTime datetime
ParentClientVisitId int UserNote nvarchar(MAX)
CreatedOn datetime
NoOfUserRequired int

Upvotes: -1

Views: 511

Answers (1)

Sanal Sunny
Sanal Sunny

Reputation: 617

Assuming that if an entry is made into Appointment table it means a user is assigned so in order to get patients unassigned to user use the below query

SELECT v.VisitId, v.PatientId From Visits v
WHERE NOT EXISTS (SELECT 1 FROM Appointment a WHERE a.VisitId=v.VisitId)

Upvotes: 0

Related Questions