以下 SQL 语句使用 PRINT 显示可靠的结果,但使用 EXEC,在“REPLACE”附近给出了不正确的语法
USE EPDB
DECLARE @Table as nvarchar(100)
DECLARE @Column as nvarchar(100)
DECLARE @Select as nvarchar(375)
DECLARE @Where as nvarchar(275)
SET @Table = 'TableABC'
SET @Column = 'ColumnABC'`enter code here`
SET @Select = 'SELECT * FROM INFORMATION_SCHEMA.COLUMNS'
SET @Where = 'CRITERIA = ''VALUE'''
-- EXEC ('SELECT * FROM INFORMATION_SCHEMA.COLUMNSWHERETABLE_NAME = ' + @Table + '''')
PRINT @Select + ' WHERE ' + REPLACE(REPLACE(@Where,'CRITERIA','TABLE_NAME'),'VALUE',@Table)
EXEC (@Select + ' WHERE ' + REPLACE(REPLACE(@Where,'CRITERIA','TABLE_NAME'),'VALUE',@Table))
不知道这里发生了什么