Building a dynamic SQL query with input from sheets

Copper Contributor

Hello!

 

I have found myself in a situation where i need to specify which data i want from an SQL database (Oracle). Then i get a prompt asking for Server, and there is a field for optional SQL statement.

 

I use the SQL statement field for specifying what data i need from the SQL database.

 

The problem: The SQL database has several tables i need to access, each with thousands of rows. I could narrow down the query but it would only make the query a bit lighter - not enough.

 

The question: Is there a way (maybe through power query or VBA) to build these SQL statements dynamically? I.e. get data from an excel sheet with IDs to fetch from the DB when the user presses Refresh? So e.g. next time the user refreshes and the list of IDs are different in the sheet, it fetches different data?

 

Thankful for any thoughts/ideas.

//M

2 Replies
So what would the SQL statement look like when the list contains e.g. 4 IDs?

@Morty93 Attached workbook contains two queries which might give you some ideas.