Use one resource query but have it connect to different DB depending on select box (mssql)

I have multiple mssql databases that have similar or even identical tables. I want to build one app that can be used across multiple databases, and the queries know which database to use based on a select box.

So I want to do something like...

USE {{selDB.value}}

SELECT * FROM addresses

Right now I have something gross like...

 IF {{selDB.value}} = 'database1'
    BEGIN
        use database1
    END
 ELSE IF {{selDB.value}} = 'database2'
 		BEGIN	
    		use database2
    END
 ELSE IF {{selDB.value}} = 'database3'
 		BEGIN	
    		use database3
    END

SELECT * from addresses

And there are a lot of databases and I have to copy and paste that into every query in the app.

Suggestions????

Is there a way to change the Resource for a query dynamically?

Hi @lvnenchak Thanks for reaching out about your use case!

It looks like this isn't currently possible to do in Retool :disappointed: I checked internally & I see that we are working on a beta feature that would help with this, but we don't have a distinct timeline yet.

I will move this post to our feature requests section for the time being! Definitely keep an eye out for this feature on our updates

1 Like

Hi, is this still not possible?

I am currently working on a project that requires running the same query on different databases,

Is there an alternative for this?

Hi @Yairlpz Thanks for checking in! Do you have this option on your resource page? An admin should be able to check this on:

If you don't see this, what resource type are you working with?