2

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.

Community
  • 1
  • 1
  • I'm trying to remove duplicates from the field i cread p5_id. That's why i'm using group by. – mark zarandi Oct 26 '12 at 14:02
  • I dont know a SQL language that will let you use parameters in a group by in the way you are trying to do it. – StingyJack Oct 26 '12 at 14:03
  • @Stingyjack has already mentioned the invalid SQL. However, regarding your question about the parameters, you'll have to use ODBC if you want to use ?-based parameters at all. The alternative, if you can only connect via OLEDB, is to write VBA code to add/edit parameters. – ExactaBox Oct 26 '12 at 14:13

1 Answers1

2

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005