0

can any one help me to convert the following query into mssql which is working on postgresql now

query is to take the updated datetime of the report in the asc order of the date

select 
count(*) as count, 
TO_CHAR(RH.updated_datetime,'dd-mm-YYYY') as date,
SUM( 
  extract ( 
    epoch from ( 
      RH.updated_datetime - PRI.procedure_performed_datetime 
    )
  )
)/count(*) as average_reporting_tat 
from 
report R, 
report_history RH, 
study S, 
procedure_runtime_information PRI, 
priorities PP, 
patient P, 
procedure PR 

where 

RH.report_fk=R.pk and RH.pk IN ( 
  select pk from ( 
    select * from report_history where report_fk=r.pk order by revision desc limit 1 
  ) as result 
  where old_status_fk IN (21, 27)
) AND R.study_fk = S.pk 
AND S.procedure_runtime_fk = PRI.pk 
AND PRI.procedure_fk = PR.pk 
AND S.priority_fk = PP.pk 
AND PRI.patient_fk = P.pk 
AND RH.updated_datetime >= '2013-05-01' 
AND RH.updated_datetime <= '2013-05-12' 
group by date
0

1 Answer 1

1

If I read your query properly, your problem is that you need to list everything in the group by clause that is in your column list which is not part of an aggregate. So your group by needs to be:

GROUP BY RH.updated_datetime

If this doesn't fix it, please post the error message you are getting.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.