I am facing a problem with output from sp_executesql
in a stored procedure in SQL Server. Below is the part of the stored procedure:
DECLARE @RET_Amt as NUMERIC(18,2)
DECLARE @v_Select nvarchar(200)
SET @v_select = 'SELECT @RET_Amt=(14315.00-10420.00) /10420.00'
exec sp_executesql @v_select,N'@RET_Amt numeric output', @RET_Amt output;
SELECT 'Return Value' = @RET_Amt
This returns an output of 0.00
which is not correct. When we just execute select clause on prompt:
select (14315.00-10420.00) / 10420.00
Output is : 0.3738003838
So sp_executesql
is rounding the result. Can someone help me to get value without rounding with sp_executesql
? My stored procedure is creating the dynamic select clause and building the query. So I have to go with sp_executesql
.
Thanks for any input!