BAQ Issue

I am trying to run a BAQ with this sql statement. When I run this in sql it works no problem. But when i run this and build it out in the BAQ it errors out. Any help with this would be greatly appreciated.

(datepart(year,POHeader.OrderDate)) as [Calculated_Year],
(count( POHeader.PONum )) as [Calculated_Count]
from Erp.POHeader as POHeader
where (POHeader.VendorNum = 9)
group by (datepart(year,POHeader.OrderDate))

Have you tried changing the Group By to [Calculated_Year] ??

or is your original post what shows up in the BAQ, when you select the GroupBy box on on the row for Calculated_Year, on the Display Columns sheet

The SQL is what is created in the BAQ. I ran it in sql just to check to see if it would work and I did not have any issues. I am not sure why it would give me some issues.

I am not sure why it is giving this erro


Seems to be causing an error because you’ve used a reserved SQL keyword as the name of a calculated field.

Delete the “count” field, and recreate it again using the same formula but use a name such as “OrderCount” and it’ll work just fine.

(for completeness of answer, I set the type for each field as INT)


Thank you sir!