You're using the wrong constant to create your first parameter (@Fx
). You create it as dbDecimal
, and dbDecimal
has a value of 20. You want to use adDecimal
, which has a value of 14. (To an ADODB.Parameter, dbDecimal = 20 = adBigInt
, which explains why your parameter values were being rounded or truncated to integers.)
Passing Double From MS Access to Stored Procedure Rounds
-
07-07-2023 - |
Frage
I have a stored procedure that is passed one variable when called from MS Access. The passed variable is an exchange rate and varies between 0.8 and 0.999. When I run the sproc through SSMS everything is correct but if I call from MS Access the FxRate inserted in the table is rounded to 1.
Stored proc (stripped down a little) is:
CREATE PROCEDURE [dbo].[usp_UpdateSKNDetailMaster]
-- Add the parameters for the stored procedure here
@Fx decimal(4,3),
@Ret int OUTPUT
AS
BEGIN
INSERT INTO dbo.tblFxRate (TRUWeek,FxRate)
VALUES (201412,@Fx)
END
Function to call is (again stripped down)
Function RefreshSKNDetailMaster(dblFx As Double) As Long
[Connections, sproc anme etc...]
Set param = cmd.CreateParameter("@Fx", dbDecimal, adParamInput, , dblFx)
param.NumericScale = 3
param.Precision = 4
cmd.Parameters.Append param
Set param = cmd.CreateParameter("@Ret", 20, adParamOutput)
cmd.Parameters.Append param
CurrentDb.QueryTimeout = 0
cmd.Execute
RefreshSKNDetailMaster = cmd.Parameters("@Ret")
End Function
Table structure:
CREATE TABLE [dbo].[tblFxRate](
[TruWeek] [int] NOT NULL,
[FxRate] [decimal](4, 3) NOT NULL,
[UID] [int] IDENTITY(1,1) NOT NULL
)
This approach seems to work fine for similar sprocs but I can't get it to work for this one. I hope I'm not missing something obvious!
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow