我相信我需要使用CAST,但这在第一个'WHERE'
上失败了 SELECT a.Patient_Number, a.Appt_DateTime, a.Appt_Resource_Descr, a.Appt_Type_Descr, a.Appt_Status, a.Appt_Sched_Department_Descr, p.Patient_Name
FROM vwGenPatApptInfo a
JOIN vwGenPatInfo p
WHERE CAST(a.Patient_Number as VARCHAR(30)) + CAST(a.Appt_DateTime as VARCHAR(30)) in (
select CAST(a.Patient_Number as VARCHAR(30)) + CAST(MIN(a.Appt_DateTime) as VARCHAR(30))
from vwGenPatApptInfo a
WHERE a.Appt_Status='A'
AND a.Appt_DateTime>={ts '2017-01-01 02:25:00'}
AND a.Appt_DateTime<{ts '2017-12-31 23:25:01'}
AND a.Appt_Sched_Department_Descr='Mental Health'
group by a.Patient_Number)
ORDER BY a.Patient_Number, a.Appt_DateTime
答案 0 :(得分:1)
这样的事情应该可以让你开始
select a.patient_number
, other fields
, min(appt_dateTime) earliestAppointment
, datename(month(min(appt_dateTime)) monthName
, datepart(month(min(appt_dateTime)) monthNumber
from yourtables
WHERE a.Appt_Status='A'
AND a.Appt_DateTime>={ts '2017-01-01 02:25:00'}
AND a.Appt_DateTime<{ts '2017-12-31 23:25:01'}
AND a.Appt_Sched_Department_Descr='Mental Health'
group by a.patient_number
order by monthNumber
您的工作是弄清楚如何获得该约会的详细信息。