What am I doing wrong here? I am getting this error on:
SELECT LEFT(SUBSTRING(batchinfo.datapath, PATINDEX(\'%[0-9][0-9][0-9]%\', batchinfo.datapath), 8000),
I think you're not using GROUP BY properly.
The point of GROUP BY is to organize your table into sections based off a certain column or columns before performing math/aggregate functions.
For example, in this table:
Name Age Salary
Bob 25 20000
Sally 42 40000
John 42 90000
A SELECT statement could GROUP BY name (Bob, Sally, and John would each be separate groups), Age (Bob would be one group, Sally and John would be another), or Salary (pretty much same result as name).
Grouping by "1" doesn't make any sense because "1" is not a column name.