我正在创建一个存储过程来创建一些基于现有列的列来进行更新,我需要做的只是在我的语句[my_database]中替换一个可用变量的数据库名称,这可能吗? / p>
DECLARE @DB_NAME VARCHAR(MAX),@TABLE VARCHAR(MAX),@ENT VARCHAR(MAX);
SET @DB_NAME = 'my_database'
SET @TABLE = 'TEST_db'
SET @ENT = 'Entidad'
IF EXISTS (SELECT COLUMN_NAME FROM [my_database].INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TABLE AND COLUMN_NAME = @ENT)
BEGIN
PRINT 'OK'
END
ELSE PRINT 'FAIL';
我的意思是以下内容。我想替换这个:
IF EXISTS (SELECT COLUMN_NAME FROM [my_database].INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TABLE AND COLUMN_NAME = @ENT)
为此:
IF EXISTS (SELECT COLUMN_NAME FROM DB_NAME.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TABLE AND COLUMN_NAME = @ENT)
如果有解决方案,请帮助我,我被困住了:(