Can't alter database with variable while procedure creation?

I'm trying to use a TSQL block to apply a procedure to all the databases in work.

DECLARE
@VMDC  VARCHAR(40),
@VADC  VARCHAR(40),
@VBDC  VARCHAR(40)

BEGIN

SET @VMDC = 'EMPRESAMDC_6666';
SET @VADC = REPLACE(@VMDC, 'MDC', 'ADC');
SET @VBDC = REPLACE(@VMDC, 'MDC', 'BDC');

USE @VMDC;
'CREATE OR ALTER PROCEDURE...'

USE @VADC;
'CREATE OR ALTER PROCEDURE...'

USE @VBDC;
'CREATE OR ALTER PROCEDURE...'

END;

I'm getting 'Incorrect syntax near @variables' while trying to do 'USE @variable'.

Is there any way to use 'USE' with variables?

EDIT: The assimilated topic does not answer my question because the proposed solution does not work with procedure creation.

Upvotes: 0

Views: 114

Answers (0)

Related Questions