I have two databases on the same SQL Server. Same code.
I have a stored procedure with an input parameter @Test INT. In one database when I pass a NUMERIC value into that input, it gets truncated and everything works fine. In the other one, when doing the same thing, I get the following error:
Error converting data type numeric to int
Here is the stored procedure signature:
CREATE PROCEDURE [dbo].[blProductGetTariff]
(
@CurrencyID INT,
@ProductID INT,
@TradeDate DATETIME,
@TotalDays INT,
@onTariff NUMERIC(22, 10) OUTPUT
)
And here's how I invoke that stored procedure:
EXEC blProductGetTariff @CurrencyID,
@MTPLY_VolumeID,
@TradeDate,
@VolumeParam,
@VolumeMultiplierRate OUTPUT
@VolumeParam is numeric and it gets fed fine into @TotalDays in one db, but not in the second one.
What would be the possible database setting responsible for this, and is there one? Or I'm missing something, and there are other reasons for this weird behaviour?
UPDATE: Darin made a very good point in one of his comments below: "Also, looking at your code above, you might be overflowing the int if you are passing a numeric(22,10). In which case you have to make the numeric smaller or pass a bigint".. He was right. So changing INT to BIGINT resolved the problem, although I still do not understand why it does not happen in the first database, where everything works fine with INT and I use exactly the same data(actually the same file) for testing.