@josecgomez hey look same problem we just had! But wait… the customer table is involved in this one too, coincidence? Perhaps not!
We just troubleshot a query where if you joined InvcHead to Customer via Company and CustNum the query would time out and say “Bad SQL” remove the customer table all good. Funny thing that’s a native index so nothing weird there. Not sure if Jose ever found out exactly what was going wrong, but running the query from the Execution Plan or the Designer window it was fine, as the BAQ not fine.
Bah, why didn’t I think of that. The last 2 queries I was stuck on for a long time were also crashing because of Company. Deleted all company from the joins and it works fine now.
geez I wonder how many of my BAQs would break on 10.2.500.2 if I had this bug I thought Epicor used ATE and Unit Tests to test each build, but we often find non-trivial bugs that could have been avoided (yeah I know im blaming .2 it could also be Data specific).
I think I might have found another problem? This super simple one also gives a bad SQL error and it has no join with customer…
select
[QuoteHed].[QuoteNum] as [QuoteHed_QuoteNum],
[Task].[TaskID] as [Task_TaskID],
[Task].[TaskSeqNum] as [Task_TaskSeqNum],
[Task].[TaskDescription] as [Task_TaskDescription],
[Task].[Conclusion] as [Task_Conclusion],
[Task].[ReasonCode] as [Task_ReasonCode]
from Erp.QuoteHed as QuoteHed
inner join Erp.Task as Task on
QuoteHed.QuoteNum = Task.Key1
Query returned 1235 row(s).
Query has no more records to return.
Query execution total time: 287.0886 ms.
select
[QuoteHed].[QuoteNum] as [QuoteHed_QuoteNum],
[Task].[TaskID] as [Task_TaskID],
[Task].[TaskSeqNum] as [Task_TaskSeqNum],
[Task].[TaskDescription] as [Task_TaskDescription],
[Task].[Conclusion] as [Task_Conclusion],
[Task].[ReasonCode] as [Task_ReasonCode]
from Erp.QuoteHed as QuoteHed
inner join Erp.Task as Task on
QuoteHed.QuoteNum = Task.Key1
select
[Task].[TaskID] as [Task_TaskID],
[Task].[TaskSeqNum] as [Task_TaskSeqNum],
[Task].[TaskDescription] as [Task_TaskDescription],
[Task].[Conclusion] as [Task_Conclusion],
[Task].[ReasonCode] as [Task_ReasonCode]
from Erp.Task as Task
inner join (select
(convert(varchar, QuoteHed.QuoteNum)) as [Calculated_calcq],
[QuoteHed].[QuoteNum] as [QuoteHed_QuoteNum]
from Erp.QuoteHed as QuoteHed
group by [QuoteHed].[QuoteNum]) as SubQuery2 on
Task.Key1 = SubQuery2.Calculated_calcq
Is that how you normally cast it?
But the BAQ I had in OP works without the casting. Very strange… so sometimes you have to cast and other times you do not.
I get that part, but if Key1 is actually a string why would it ever work without casting (not counting string ↔ string joins)? For example in my original BAQ I had:
And it works, but the second BAQ I posted, I used the same fields and it did not work, until casting was added. That was the cherry on top as far as confusion goes.
Task.Key1 is NVarchar(50) and QuoteHed.QuoteNum is Numeric.
So you need to cast the QuoteNum as NVarchar(50) to make it similar to Task.Key1
On your BAQ you should have something like this:
select
[QuoteHed].[QuoteNum] as [QuoteHed_QuoteNum],
[Task].[TaskID] as [Task_TaskID],
[Task].[TaskSeqNum] as [Task_TaskSeqNum],
[Task].[TaskDescription] as [Task_TaskDescription],
[Task].[Conclusion] as [Task_Conclusion],
[Task].[ReasonCode] as [Task_ReasonCode]
from Erp.QuoteHed as QuoteHed
inner join Erp.Task as Task on
Task.Key1 = Convert(NVARCHAR(50), QuoteNum)
So on the inner join definition, add the following expression: Convert(NVARCHAR(50), QuoteNum)