Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. numeric data type value

numeric data type value

Scheduled Pinned Locked Moved Database
helpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    For_IT
    wrote on last edited by
    #1

    Hi My table has one column "vat_percentage" as numeric(2,2) data type. when I try to insert values using INSERT INTO [dbo].[cp_vat] ([vat_text],[vat_percentage],[vat_valid_from],[vat_valid_to]) values ('test',10.2,05/2005/05,05/05/2007) I get an error as Arithmetic overflow error converting numeric to data type numeric. can someone pls help me?

    M H 2 Replies Last reply
    0
    • F For_IT

      Hi My table has one column "vat_percentage" as numeric(2,2) data type. when I try to insert values using INSERT INTO [dbo].[cp_vat] ([vat_text],[vat_percentage],[vat_valid_from],[vat_valid_to]) values ('test',10.2,05/2005/05,05/05/2007) I get an error as Arithmetic overflow error converting numeric to data type numeric. can someone pls help me?

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      That will be your dates. Best practice is to use ISO format dates, yyyymmdd, as these are not sensitive to the selected locale, so you would write your statement as:

      INSERT INTO [dbo].[cp_vat]
      ([vat_text],[vat_percentage],[vat_valid_from],[vat_valid_to])
      values
      ('test',10.2,'20050505','20070505')

      Note that date literals are entered as strings, not numbers - if you pass a number, it will be treated as the binary representation and you'll get the wrong answer. If you're passing these dates in from application code, you should use parameterised queries and the appropriate Parameters collection. Stability. What an interesting concept. -- Chris Maunder

      F 1 Reply Last reply
      0
      • M Mike Dimmick

        That will be your dates. Best practice is to use ISO format dates, yyyymmdd, as these are not sensitive to the selected locale, so you would write your statement as:

        INSERT INTO [dbo].[cp_vat]
        ([vat_text],[vat_percentage],[vat_valid_from],[vat_valid_to])
        values
        ('test',10.2,'20050505','20070505')

        Note that date literals are entered as strings, not numbers - if you pass a number, it will be treated as the binary representation and you'll get the wrong answer. If you're passing these dates in from application code, you should use parameterised queries and the appropriate Parameters collection. Stability. What an interesting concept. -- Chris Maunder

        F Offline
        F Offline
        For_IT
        wrote on last edited by
        #3

        Mik, I used the string given by u, but still the error persists :( Arithmetic overflow error converting numeric to data type numeric.

        M 1 Reply Last reply
        0
        • F For_IT

          Mik, I used the string given by u, but still the error persists :( Arithmetic overflow error converting numeric to data type numeric.

          M Offline
          M Offline
          Mairaaj Khan
          wrote on last edited by
          #4

          What Mik said about date literals, is right. The precision is the total number of digits in the number, and the scale is the number of digits to right of the decimal point in the number. see here[^] You defined the field vat_percentage as numeric (2,2), means numeric field with precision 2 and scale 2. Now in this scenario the problem is with the numeric value that you given, which is 10.2, even if you enter 1 you will get the same error message. With your defined precision and scale you can only enter values like this: 0.23. If you entered .23987, it will round to .24 Or Alternatively change the field definition to numeric(4,2) that is total number of digits will be 4. Among them 2 digits will be at right of the decimal point. Hope this would solve your problem. Regards _____________________________ Success is not something to wait for, its something to work for.

          F 1 Reply Last reply
          0
          • M Mairaaj Khan

            What Mik said about date literals, is right. The precision is the total number of digits in the number, and the scale is the number of digits to right of the decimal point in the number. see here[^] You defined the field vat_percentage as numeric (2,2), means numeric field with precision 2 and scale 2. Now in this scenario the problem is with the numeric value that you given, which is 10.2, even if you enter 1 you will get the same error message. With your defined precision and scale you can only enter values like this: 0.23. If you entered .23987, it will round to .24 Or Alternatively change the field definition to numeric(4,2) that is total number of digits will be 4. Among them 2 digits will be at right of the decimal point. Hope this would solve your problem. Regards _____________________________ Success is not something to wait for, its something to work for.

            F Offline
            F Offline
            For_IT
            wrote on last edited by
            #5

            Thanks a lot

            1 Reply Last reply
            0
            • F For_IT

              Hi My table has one column "vat_percentage" as numeric(2,2) data type. when I try to insert values using INSERT INTO [dbo].[cp_vat] ([vat_text],[vat_percentage],[vat_valid_from],[vat_valid_to]) values ('test',10.2,05/2005/05,05/05/2007) I get an error as Arithmetic overflow error converting numeric to data type numeric. can someone pls help me?

              H Offline
              H Offline
              Heinz_
              wrote on last edited by
              #6

              Check out your decimal separator. Try to use ',' instead of '.'

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups