Query for Multiple Patient Field Defs
Posted: Tue Feb 20, 2018 6:20 pm
Query Help Needed!
I am trying to write a query to return a "table" with the field names and field values for multiple patient field definitions. Is this possible? Every query example from the Open Dental website that returns patient definition fields only returns one field and one value. The goal of this query is to return the Patient Name for patients that have a field value for PatFieldName1 and also show the field value for the PatFieldName2. Here is what I have so far:
SET @PatFieldName1='H&P Signed by MD/PO/PA';
SET @PatFieldName2 = 'H&P Received';
SET @pos=0;
SELECT @pos:=@pos+1 AS 'Count', A.*
FROM (
SELECT CONCAT(p.LName,', ',p.FName) AS 'Patient Name',
pf.FieldName,
pf.FieldValue
FROM patient p
INNER JOIN patfield pf ON pf.PatNum=p.PatNum
AND pf.FieldName LIKE @PatFieldName1
ORDER BY p.LName, p.FName
) A
I am trying to write a query to return a "table" with the field names and field values for multiple patient field definitions. Is this possible? Every query example from the Open Dental website that returns patient definition fields only returns one field and one value. The goal of this query is to return the Patient Name for patients that have a field value for PatFieldName1 and also show the field value for the PatFieldName2. Here is what I have so far:
SET @PatFieldName1='H&P Signed by MD/PO/PA';
SET @PatFieldName2 = 'H&P Received';
SET @pos=0;
SELECT @pos:=@pos+1 AS 'Count', A.*
FROM (
SELECT CONCAT(p.LName,', ',p.FName) AS 'Patient Name',
pf.FieldName,
pf.FieldValue
FROM patient p
INNER JOIN patfield pf ON pf.PatNum=p.PatNum
AND pf.FieldName LIKE @PatFieldName1
ORDER BY p.LName, p.FName
) A