Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with integer conversion
Message
From
11/09/2013 18:51:21
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Problem with integer conversion
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01582916
Message ID:
01582916
Views:
52
Hi all -

I am really puzzling over this one. This code
oCommand.CommandText = "INSERT INTO [TIP_AmendmentApprovedFunding] (AmendmentNumber, TipID, Amount, Fundtype, Year, Phase) "
oCommand.CommandText += "SELECT @AmendmentNumber, TipID, Amount, Fundtype, Year, Phase "
oCommand.CommandText += "FROM [TIP_ApprovedFunding] WHERE (TipID = @TipID and year > @AmendmentNumber-1 and year < @AmendmentNumber+4)"
oCommand.ExecuteNonQuery()
has been working fine for months. Today all of a sudden it no longer works. With a value of 2014.05 for the @AmendmentNumber, it crashes with an error that says it can't convert the varchar value '2014.05' to an integer. Why it wants to convert it to an integer is beyond me. The field it's going into is a number(7,2) field.
So anyway, I thought I would help it along so I changed the code to this
oCommand.CommandText = "INSERT INTO [TIP_AmendmentApprovedFunding] (AmendmentNumber, TipID, Amount, Fundtype, Year, Phase) "
oCommand.CommandText += "SELECT @AmendmentNumber, TipID, Amount, Fundtype, Year, Phase "
oCommand.CommandText += "FROM [TIP_ApprovedFunding] WHERE (TipID = @TipID and year between convert(integer, @AmendmentNumber) and convert(integer, @AmendmentNumber + 4))"
oCommand.ExecuteNonQuery()
but it renders the same error. The parameter value is set like this
oCommand.Parameters.AddWithValue("@AmendmentNumber", Amendments_DDL.SelectedValue)
Any thoughts?
Thanks
Next
Reply
Map
View

Click here to load this message in the networking platform