It seems like this approach for setting sqlcmd variable does not work so I am wondering if there is another way?
DECLARE @d varchar(max);
SET @d = 'foobar';
:setvar database @d
USE $(database)
Note: I realized that using :setvar in this manner works but I want to set it using a variable in the T-SQL script instead of explicitly setting it.
:setvar database "foobar"