Forum Discussion

altoma75's avatar
altoma75
Copper Contributor
Dec 13, 2022

Customize a parameter query with a string

I have a SQL query written and saved in Excel.

In the where clause I can use:

where dept = ?

and then set the parameter to reference a cell where the user inputs their dept.

However, I need to be able to enter a string of departments and change my where to an 'in' instead of '='.

I need it to be: where dept in (xxxx,xxxx,xxxx).

How can I write this and use the ? parameter to reference a list of depts and have the string of departments saved in a cell?

1 Reply

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor
    concatenate sql string before run it?
    like
    s="select * from aa where f1 in (" & cells(1,1) & ")"
    rs.open cnn,s

Resources