Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with integer conversion
Message
De
11/09/2013 19:41:04
 
 
À
11/09/2013 18:51:21
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01582916
Message ID:
01582921
Vues:
48
>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

Since you want the number as an integer anyway, round it and cast it as an integer variable to use in the Where clause before you to do the Insert


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform