Hi,
I have the following query (A);
SELECT TOP (100) PERCENT PracID, CAST(PatID AS Varchar(10)) + CAST(PracID AS varchar(10)) AS PatientID, PersonID, PatientGuidDigest
FROM (SELECT PracID, PersonID, PatientGuidDigest, row_number() OVER (partition BY pracid
ORDER BY pracid) AS PatID
FROM dbo.EmisPatientExtraction_RtnPatID_NULLs WITH (tablock)) t
ORDER BY PracID, PatID
The above query works OK, and generates the PatientIDs, however, I want the PatientID to be a follow up of the Max Value of PatientID in another table (EmisPatient1)
So, for example, if the Max Value of PatientID in the table for a particular practice (e.g., 20001) is 10002,
I want the next PatientID generated from the above query to follow up i.e., it will be 1000320001 and so on ....
The other table dbo.EmisPatient1 has the following fields;
PatientID, PatientNo, PracID, PersonID.
For example in table EmisPatient1,
PatientID PatientNo PracID PersonID
2320001 16 20001 1
2420001 17 20001 2
2520021 18 20021 1
6720021 19 20021 2
I want the query to extract any patients in the two practices as shown below as a start up - i.e., follow up of the PatientID as in the EMISPatient1 table; Note - 25 (is an incremental value and 20001 is the PracID)
PatientID PatientNo PracID PersonID
2520001 178 20001 7
6820021 9 20021 4
Any help will be indeed appreciated..
Many Thanks