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. Conversion failed in sql

Conversion failed in sql

Scheduled Pinned Locked Moved Database
databasehelpbusiness
9 Posts 6 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.
  • V Offline
    V Offline
    venkatesann
    wrote on last edited by
    #1

    Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic

    Conversion failed when converting the varchar value '12r' to data type int.
    declare @t table
    (
    val varchar(10)
    )
    insert into @t
    select '1' union
    select '2' union
    select '3' union
    select '4' union
    select 'et' union
    select '4' union
    select '6' union
    select '7' union
    select '8' union
    select '9' union
    select '12r'

    select * from @t where cast(val as int) > 3

    L G M B 4 Replies Last reply
    0
    • V venkatesann

      Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic

      Conversion failed when converting the varchar value '12r' to data type int.
      declare @t table
      (
      val varchar(10)
      )
      insert into @t
      select '1' union
      select '2' union
      select '3' union
      select '4' union
      select 'et' union
      select '4' union
      select '6' union
      select '7' union
      select '8' union
      select '9' union
      select '12r'

      select * from @t where cast(val as int) > 3

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      12r cannot be converted because it is not a number.

      Use the best guess

      1 Reply Last reply
      0
      • V venkatesann

        Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic

        Conversion failed when converting the varchar value '12r' to data type int.
        declare @t table
        (
        val varchar(10)
        )
        insert into @t
        select '1' union
        select '2' union
        select '3' union
        select '4' union
        select 'et' union
        select '4' union
        select '6' union
        select '7' union
        select '8' union
        select '9' union
        select '12r'

        select * from @t where cast(val as int) > 3

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        Try this:

        select *
        from @t
        where
        cast((case when isnumeric(val) = 1 then val else 0 end) as int) > 3

        Edit -this will turn the 12r into a zero as it is not a valid integer.

        “That which can be asserted without evidence, can be dismissed without evidence.”

        ― Christopher Hitchens

        1 Reply Last reply
        0
        • V venkatesann

          Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic

          Conversion failed when converting the varchar value '12r' to data type int.
          declare @t table
          (
          val varchar(10)
          )
          insert into @t
          select '1' union
          select '2' union
          select '3' union
          select '4' union
          select 'et' union
          select '4' union
          select '6' union
          select '7' union
          select '8' union
          select '9' union
          select '12r'

          select * from @t where cast(val as int) > 3

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          This question really does ask for a disparaging response. If you can't work out that declaring a field of type int and trying to stuff text into it is going to fail and then cannot understand the very clear error message you should stop now and get an education.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • V venkatesann

            Hi All, I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic

            Conversion failed when converting the varchar value '12r' to data type int.
            declare @t table
            (
            val varchar(10)
            )
            insert into @t
            select '1' union
            select '2' union
            select '3' union
            select '4' union
            select 'et' union
            select '4' union
            select '6' union
            select '7' union
            select '8' union
            select '9' union
            select '12r'

            select * from @t where cast(val as int) > 3

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Perhaps JavaScript could cast '12r' into an int with a value of 12, but many other programming/scripting languages won't do so.

            M 1 Reply Last reply
            0
            • B Bernhard Hiller

              Perhaps JavaScript could cast '12r' into an int with a value of 12, but many other programming/scripting languages won't do so.

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              Bernhard Hiller wrote:

              JavaScript could cast '12r' into an int

              It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!

              Never underestimate the power of human stupidity RAH

              G R 2 Replies Last reply
              0
              • M Mycroft Holmes

                Bernhard Hiller wrote:

                JavaScript could cast '12r' into an int

                It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!

                Never underestimate the power of human stupidity RAH

                G Offline
                G Offline
                GuyThiebaut
                wrote on last edited by
                #7

                Mycroft Holmes wrote:

                There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!

                Considering how close K and M are on a qwerty keyboard :omg:

                “That which can be asserted without evidence, can be dismissed without evidence.”

                ― Christopher Hitchens

                1 Reply Last reply
                0
                • M Mycroft Holmes

                  Bernhard Hiller wrote:

                  JavaScript could cast '12r' into an int

                  It does, how extraordinary, no wonder I loathe the script language. There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!

                  Never underestimate the power of human stupidity RAH

                  R Offline
                  R Offline
                  Richard Berry100
                  wrote on last edited by
                  #8

                  Mycroft, I see original poster did not respond, but really curious - what does J-script convert '12r' to???

                  M 1 Reply Last reply
                  0
                  • R Richard Berry100

                    Mycroft, I see original poster did not respond, but really curious - what does J-script convert '12r' to???

                    M Offline
                    M Offline
                    Mycroft Holmes
                    wrote on last edited by
                    #9

                    Richard.Berry100 wrote:

                    what does J-script convert '12r' to???

                    Dammed if I know, as a Silverlight dev I don't have to get my hands grubby by rabbiting around in script languages. The r probably stands for a currency sign, I image the conversion just drops the non numeric characters and turn the rest to an integer.

                    Never underestimate the power of human stupidity RAH

                    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