最后的变量为什么是NULL值
如下操作
declare
@sql1 varchar(8000),
@v_database varchar(10),
@VALUE varchar(5);
select 'CHINA' AS NAME ,'960' AS VALUE INTO TABLE1
SET @v_database = 'GZ'
set @sql1='SELECT' +@VALUE+'=VALUE FROM '+@V_database+ '.dbo.TABLE1 WHERE NAME = ''CHINA'''
exec(@sql1)
select @VALUE
结果是NULL,为什么不是等于960,谢谢 变量赋值 NULL
[解决办法]
select 'CHINA' AS NAME ,'960' AS VALUE INTO TABLE1
declare
@sql1 nvarchar(4000),
@v_database nvarchar(10),
@VALUE nvarchar(5);
SET @v_database = 'GZ'
set @sql1='SELECT @VALUE=VALUE FROM '+@V_database+ '.dbo.TABLE1 WHERE NAME = ''CHINA'''
EXEC sys.sp_executesql @sql1,N'@VALUE nvarchar(5) output',@VALUE OUTPUT
select @VALUE