Hi,
I have the following query;
ORIGINAL CODE -
Query A
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 EMISPatientExtraction WITH (tablock)) t
ORDER BY PracID, PatID
Results
PracID PatientID
20001 120001
20001 220001
..
..
20001 24520001
20002 120002
20002 220002
..
..
20002 35620002
20003 NULL
20003 NULL
Now, I have another query (qryMaxValue) that reads the MAX PatID i.e.,
Query B
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
that gives the results;
PracID PatID
20001 245
20002 356
20003 NULL
Query C
SELECT TOP (100) PERCENT PracID, 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
Now, I want to join these 2 queries (Query B & Query C) so that the result will be for the NEXT PatientIDs in the query below;
PracID PatID
20001 24620001
20001 24720001
20001 24820001 ......
20002 35720002
20002 35820002....
20003 120003
20003 220003....
Thank you so much