0

I need some guidance in modifying a SQL query.

There are 2 tables (Orders & OrdersArchived) with the same column names. I understand that usig the AS to alias the name is how to deal with the duplicate names, but I can't work out how to incorporate this into a query that already uses aliases to pick up the hours from a date.

My original query is:

sSQL = "SELECT DATEPART(Hour, orderDate) AS [OrderHour], COUNT(*) AS [sCount]
FROM Orders
WHERE CAST(orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"'
GROUP BY DATEPART(Hour, orderDate) ORDER BY OrderHour"  

and this works fine from the Orders table but I cant expand it to work from the 2 tables.

Darren Cook
  • 661
  • 4
  • 14
  • 28

1 Answers1

0

You need to add table aliases. I used "o" as an example

sSQL = "SELECT DATEPART(Hour, o.orderDate) AS [OrderHour], COUNT(*) AS [sCount]
FROM Orders o
WHERE CAST(o.orderDate AS DATE) Between '"&sStartDate&"' And '"&sEndDate&"'
GROUP BY DATEPART(Hour, o.orderDate) ORDER BY o.OrderHour"  
divan
  • 29
  • 2