dbo.UDF_CONVERSION (7.68,1,null,null,25,5)
有公式
(7.68/1000.00)/1.0026
并将答案返回为0.007680000
DECLARE @A nVARCHAR(1000),@i float
SELECT @A= dbo.UDF_CONVERSION (7.68,1,null,null,25,5)
SELECT @A='SELECT '+@A
exec @i=sp_executesql @A
select @i
当我执行上述操作时,我得到的值是0
我想要0.007680000
,以便我可以使用该值进行进一步处理。
答案 0 :(得分:1)
尝试一些简单的方法:
DECLARE @i float --If your function returns float...
SELECT @i = dbo.UDF_CONVERSION (7.68,1,null,null,25,5)
--DEBUG (remove PRINT comment)
--PRINT @i
如果您需要CONVERT sp_executesql
中的值DECLARE @A nVARCHAR(1000),@i float
DECLARE @ParmDefinition nvarchar(500);
SET @A= dbo.UDF_CONVERSION (7.68,1,null,null,25,5)
SET @A = N'SELECT @retvalOUT = CONVERT(float, '''+ @A +''')'
SET @ParmDefinition = N'@retvalOUT float OUTPUT';
EXEC sp_executesql @A, @ParmDefinition, @retvalOUT = @i OUTPUT;
SELECT @i
答案 1 :(得分:0)
我写这篇文章并不好,但你可以用临时表来实现你想要的目标。
DECLARE @A nVARCHAR(1000),@i float, @retVal int
--drop table #tblReturnedVal
create table #tblReturnedVal (val float)
SELECT @A= dbo.UDF_CONVERSION (7.68,1,null,null,25,5)
SELECT @A='insert into #tblReturnedVal SELECT '+@A
exec @retVal = sp_executesql @A
select top 1 @i = val from #tblReturnedVal
select @i
select @retVal -- 0 = sp_executesql ran successfully,
-- otherwise something went wrong
编辑:你绝对应该这样做@Mate建议