Search code examples
sqlexceloledb

OLEDB Named Parameters and Group By: "?" won't work


Possible Duplicate:
GROUP BY using parameters in SQL

Here is my SQL string for a OLEDB query of a .xlsx file

szSQL = "SELECT cawo_wo_id, wows_step_id, wows_description, wffj_cur_state_desc, cawo_wo_id & wows_step_id AS p5_id FROM [" & SourceSheet$ & "$" & sourceRange$ & "] WHERE [wows_description] like '%ECR%';"

I understand that named parameters are not supported by OLEDB, but why will it not work with a 'group by' using "?" as the parameter?

Like so:

szSQL = "SELECT cawo_wo_id, wows_step_id, wows_description, wffj_cur_state_desc, cawo_wo_id & wows_step_id AS p5_id FROM [" & SourceSheet$ & "$" & sourceRange$ & "] WHERE [wows_description] like '%ECR%' GROUP BY ?;"

Thanks for any help.


Solution

  • Doing that would group on the value that you send as the parameter value, and grouping on a literal value is not allowed.

    If you want to group on different fields dynamically, you have to create the query dynamically, not put the field name in a parameter.