在sqlserver中执行动态sql语句获得单个值
CREATE PROCEDURE getdsqlvalue @sqlstr nvarchar(500),@result nvarchar(150) output
AS
set @sqlstr='set @result=('+@sqlstr+')'
EXEC sp_executesql @sqlstr,N'@result varchar(500) out',@result out
set @result = isnull(@result,'')
return
GO
CREATE PROCEDURE getdsqlvalue @sqlstr nvarchar(500),@result nvarchar(150) output
AS
set @sqlstr='set @result=('+@sqlstr+')'
EXEC sp_executesql @sqlstr,N'@result varchar(500) out',@result out
set @result = isnull(@result,'')
return
GO