I need to determine the last transaction for an item. I have a transaction table that has a date column and a time column. Because I need the max date and then the max time within the max date, a single Access query did not work. I can do it with multiple queries but was trying to keep it to one.
I have the following SQL script which works beautifully in Management Studio. I thought I could copy and paste it into Access query/SQL View but it doesn’t work:
SELECT hbt.PartNum, hbt.TranType, hbt.TranQty, (CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time))
FROM [SysproCompany1].[dbo].[HB_TRANSHISTORY] as hbt,
(SELECT max(CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time)) as maxPostDate, PartNum
from HB_TRANSHISTORY
Group by PartNum) maxresults
where hbt.PartNum = maxresults.PartNum and (CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time)) = maxresults.maxPostDate and hbt.TranType = 1
order by hbt.PartNum
I get the following error:
“Syntax error (missing operator) in query expression ‘(CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time))’
Does anyone know the proper syntax for this or am I trying to do something that can’t be done in Access in one query?
I have the following SQL script which works beautifully in Management Studio. I thought I could copy and paste it into Access query/SQL View but it doesn’t work:
SELECT hbt.PartNum, hbt.TranType, hbt.TranQty, (CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time))
FROM [SysproCompany1].[dbo].[HB_TRANSHISTORY] as hbt,
(SELECT max(CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time)) as maxPostDate, PartNum
from HB_TRANSHISTORY
Group by PartNum) maxresults
where hbt.PartNum = maxresults.PartNum and (CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time)) = maxresults.maxPostDate and hbt.TranType = 1
order by hbt.PartNum
I get the following error:
“Syntax error (missing operator) in query expression ‘(CAST(Cast(PostDate as DATE) as DateTime) + CAST(PostTime as Time))’
Does anyone know the proper syntax for this or am I trying to do something that can’t be done in Access in one query?