一个关于动态表名调用的小问题
DECLARE @sql nvarchar(max),
@xxxxx int ,
@Pdate varchar(100)
set @Pdate=1308
set @xxxxx=( select count(id) from [1308] )
--这里正常
SET @sql = N'
SET @xxxxx=(select count(id) from '+QUOTENAME(@Pdate) +' )
'
EXEC sp_executesql @sql
PRINT @xxxxx
DECLARE @sql nvarchar(max),
@xxxxx int ,
@Pdate varchar(100)
set @Pdate=1308
set @xxxxx=( select count(id) from [1308] )
--这里正常
SET @sql = N'SET @xxxxx=(select count(id) from '+QUOTENAME(@Pdate) +')'
EXEC sp_executesql @sql ,N'@xxxxx int output',@xxxxx=@xxxxx output
PRINT @xxxxx
DECLARE @sql nvarchar(max),
@xxxxx int ,
@Pdate varchar(100)
set @Pdate='1308'
set @xxxxx=( select count(id) from [1308] )
--这里正常
SET @sql = N'DECLARE @xxxxx int;
SET @xxxxx=(select count(id) from '+QUOTENAME(@Pdate) +' )
'
EXEC sp_executesql @sql
PRINT @xxxxx