SQL SERVER 动态语句实例
DECLARE @FSQ VARCHAR(2000) DECLARE @COLUMN VARCHAR(200) declare @CS VARCHAR(200)='管理员' SET @COLUMN='USERNAME' SET @FSQ='SELECT '+@COLUMN+' FROM SYS_USER where '+@COLUMN+' = ''管理员'' ' PRINT @FSQ SET @FSQ='SELECT '+@COLUMN+' FROM SYS_USER where '+@COLUMN+' = '''+@CS+'''' PRINT @FSQ EXEC (@FSQ) SELECT USERNAME FROM SYS_USER where USERNAME = '管理员' SELECT USERNAME FROM SYS_USER where USERNAME = '管理员'