I have this query in C# and I have tried to add group by for all non-aggregate values but it does not function.
I have 3 tables:
- First table I have
assemblyno,part_no,rout_no(unique),wo_no, etc... - On the second I have
wo_no(same from table 1) andjob_no, this is the "link" table between 1 and 3 - And third table the
job_no(same as second table) withorder_val
Have to extract for a given rout_no in 1st table the max(order_val) on the third table using the second table that will link wo_no and job_no...
I hope is more clear.
Error:
Additional information: SQL: GROUP BY clause is missing or invalid.
sql = string.Format(@" SELECT t1.assemblyno, t1.level, t1.wo_no, t1.rout_no, t1.due_date, t1.printed, t1.rev_no, t2.lot, t2.po, t2.qty_due, t3.comment, t3.jobno, MAX(t3.order_val), t3.part_no,t3.po,t3.price, t3.qty_order, t3.quote_no, t3.rev_no
FROM ('{0}') t1
LEFT JOIN ('{1}') t2
on t1.wo_no = 2.wo_no
LEFT JOIN ('{2}') t3
on t2.jobno = t3.jobno
GROUP BY t1.assemblyno, t1.level, t1.wo_no, t1.rout_no, t1.due_date, t1.printed, t1.rev_no, t2.lot, t2.po, t2.qty_due, t3.comment, t3.jobno,t3.part_no,t3.po,t3.price, t3.qty_order, t3.quote_no, t3.rev_no
WHERE t1.rout_no=" + "\'" + rNum + "\'" + ";", databaseTable_WOROUTH, databaseTable_WOJOBS, databaseTable_SOMAST);