Hi,
I have the following query;
dbo.QryMaxPatID
SELECT TOP (100) PERCENT (MAX(dbo.EmisPatient1.PatientID) / 100000 + 1) * 1 AS PatID, dbo.EmisCreatePatList1.PracID
FROM dbo.EmisCreatePatList1 LEFT OUTER JOIN
dbo.EmisPatient1 ON dbo.EmisCreatePatList1.PracID = dbo.EmisPatient1.PracID
GROUP BY dbo.EmisCreatePatList1.PracID
ORDER BY dbo.EmisCreatePatList1.PracID
Results
PatID PracID
20378 20001
1901 20002
30000 20003
Now, I have the query that joins the PatID and PracID - presently PatientID is NULL in dbo.QryPatID_Rtn.
I want it to READ the PatID from dbo.QryMaxPatID and set it as the start value.
SELECT TOP (100) PERCENT PracID, CAST(PatID AS Varchar(10)) + CAST(PracID AS varchar(10)) AS PatientID
FROM (SELECT PracID, row_number() OVER (partition BY pracid
ORDER BY pracid) AS PatID
FROM dbo.QryPatID_Rtn WITH (tablock)) t
ORDER BY PracID, PatID
Therefore, the result will be;
PatientID PracID
2037820001 20001
2037920001 20001
2038020001 20001 ....
190120002 20002
190220002 20002....
3000020003 20003
3000120003 20003
3000220003 20003
I hope you got the logic, thank you so much