1

Here's the working SQL Statement:

DECLARE @LayOdds DEC = 1.5
DECLARE @Umarketiduselectionid VARCHAR(50) = '1.12677402748783'

UPDATE [dbo].[Fixtures]
SET [Fixtures].[Percent] = [Fixtures].[BackOdds] / @LayOdds * 100 - 100
WHERE [Fixtures].[MarketSelectionId] = @Umarketiduselectionid

Here's my incorrect C# Statement:

string sql = "Update Fixtures SET Percent = BackOdds / @LayOdds * 100 - 100 WHERE MarketSelectionId = @Umarketiduselectionid";

using (var cmd = new SqlCommand(sql, con))
{
    cmd.Parameters.Add("@LayOdds", SqlDbType.Decimal).Value = layOdds;
    cmd.Parameters.Add("@Umarketiduselectionid", SqlDbType.VarChar).Value = umarketiduselectionid;
    con.Open();
    cmd.ExecuteNonQuery();
}

Getting Incorrect syntax near the keyword 'Percent'.

6
  • 1
    Percent is a reserved word. Try [Percent]. Commented Sep 18, 2016 at 23:53
  • 1
    Why are you passing in numeric values as a string? Commented Sep 18, 2016 at 23:54
  • Thank you Jim - worked beautifully. Had a feeling when I defined that column as 'Percent' that it might conflict somewhere along the line lool. Spotted that and edited just as you were commenting Gordon. Commented Sep 19, 2016 at 0:02
  • What's the protocol here guys? Shall I answer it with your resolution, Jim, or delete the question? Commented Sep 19, 2016 at 0:06
  • 1
    Possible duplicate of Getting syntax error in INSERT INTO statement Commented Sep 19, 2016 at 18:01

1 Answer 1

1

Answer provided kindly by Jim Hewitt above. Many thanks.

Percent is a reserved word. Try [Percent].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.