Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How can I get this column in my query?

I want to have a column called "patientname" as part of my recordset. My strategy is to include what I'm working on with another query, so the columns have to match.

This works:

User generated image
This does not:

User generated image
The challenge is the name. I want to combine the first name (fname) with the last name (lname) and include that as a column in my recordset. But I can't do that without including "patientname" as part of the GROUP BY clause and that's where I'm running into problems.

How can I fix that?

SELECT
'C' AS txntype,
SUM(amount) AS amount,
dos,
pfirst+' '+plast as patientname, //how do I include "patientname" as a column when it's not a field in my table
'Medical Oncology' AS physicianid,
encountercode
FROM [PCAR_Data].[dbo].[txn]
WHERE
type='C'
AND
accountid=9949388
GROUP BY encountercode, dos
having max(txn.created) > DATEADD(DAY, -45, GETDATE())
ORDER by dos ASC
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

That'll do it!

Thank you!