Hi,
I'm pretty sure that you can't use the IN operator when using SQL in Excel, but has anyone got a workaround for this?
I have a query that has 10 "regions" and I want to be able to use a SQL query like the following:
Select * from table
where region in ('1'', '2', '3', '4', '5', '6', '7', '8', '9', '10')
and year = 2011
and month = 1
The regions and year and month will change, so I want to have the query like so:
Select * from table
where region in ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?')
and year = ?
and month = ?
However, when excel get's it's hands on the query, it comes out like this:
Select * from table
where region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
etc....
I have a lot of different queries that are similar and when I am assigning the parameters to each one, it gets very tedious (i.e. 30 parameters in this query).
Is there any way that I can use a range in Excel with this SQL query, or does anyone have any avice that can help me?
If you need anymore information, let me know.
Cheers,
Eoin
I'm pretty sure that you can't use the IN operator when using SQL in Excel, but has anyone got a workaround for this?
I have a query that has 10 "regions" and I want to be able to use a SQL query like the following:
Select * from table
where region in ('1'', '2', '3', '4', '5', '6', '7', '8', '9', '10')
and year = 2011
and month = 1
The regions and year and month will change, so I want to have the query like so:
Select * from table
where region in ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?')
and year = ?
and month = ?
However, when excel get's it's hands on the query, it comes out like this:
Select * from table
where region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
region = ?
and year = ?
and month = ? or
etc....
I have a lot of different queries that are similar and when I am assigning the parameters to each one, it gets very tedious (i.e. 30 parameters in this query).
Is there any way that I can use a range in Excel with this SQL query, or does anyone have any avice that can help me?
If you need anymore information, let me know.
Cheers,
Eoin