Use a specific database depending on the state

Is there any way to use a specific database based on a certain condition? To clarify, I will give a naive example:

CASE 
    WHEN @dbnum = 1 THEN USE Db1
        ELSE USE DefaultDb
END
+3
source share
1 answer

You can do this with IF:

IF @dbnum = 1
    USE Db1;
ELSE
    USE DefaultDb;
+6
source

Source: https://habr.com/ru/post/1746582/


All Articles