Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to display all the distinct orders that were placed per hour of the day for the last month. Please Help! Thanks
SQL
SELECT a.PatientAccountID
,b.OrderSubTypeAbbr
,b.CreationTime
 
FROM PatientVisit a with( nolock) 
INNER JOIN Order b with( nolock) 
ON a.PatientVisit_oid=b.PatientVisit_oid
WHERE a. VisitTypeCode ='IP'

AND b.OrderSubTypeAbbr IN ('CT Scan','MRI')
AND b.CreationTime >=DATEADD(m,-1,GETDATE())
ORDER BY a.PatientAccountID
Posted
Comments
Umer Akram 27-Jan-15 2:18am    
can you share some sample data and what's your desired output will be look like? this will help to understand your problem better.

1 solution

SQL
WHERE a. VisitTypeCode ='IP'

AND b.OrderSubTypeAbbr IN ('CT Scan','MRI')

-- to filter by month
AND month(b.CreationTime) >= @month -- ' get month from design  'parameter''

-- to filter by hour
and DATEPART(hour,b.CreationTime) = @hour -- get it from design 'parameter'

ORDER BY a.PatientAccountID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900