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. SQL Server 2008 - Number Manipulation

SQL Server 2008 - Number Manipulation

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelp
4 Posts 3 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.
  • A Offline
    A Offline
    ac011
    wrote on last edited by
    #1

    Hi All, I'm very new to SQL Server 2008, and need a bit of help manipulating numbers. I've got a int column holding numbers up to 11 digits. I need to do the following manipulation and use it in a SQL query. Basically, the first digit is transfered to the 3rd position on the right side. 12345678 23456178 or 1234 2134 The values are variable, there are even records with only a value of 1. Thanks in advance.

    L R 2 Replies Last reply
    0
    • A ac011

      Hi All, I'm very new to SQL Server 2008, and need a bit of help manipulating numbers. I've got a int column holding numbers up to 11 digits. I need to do the following manipulation and use it in a SQL query. Basically, the first digit is transfered to the 3rd position on the right side. 12345678 23456178 or 1234 2134 The values are variable, there are even records with only a value of 1. Thanks in advance.

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

      ac011 wrote:

      Basically, the first digit is transfered to the 3rd position on the right side.

      • Cast the column to a VARCHAR
      • Reararrange the characters using the string-functions described here[^]

      I are Troll :suss:

      1 Reply Last reply
      0
      • A ac011

        Hi All, I'm very new to SQL Server 2008, and need a bit of help manipulating numbers. I've got a int column holding numbers up to 11 digits. I need to do the following manipulation and use it in a SQL query. Basically, the first digit is transfered to the 3rd position on the right side. 12345678 23456178 or 1234 2134 The values are variable, there are even records with only a value of 1. Thanks in advance.

        R Offline
        R Offline
        RyanEK
        wrote on last edited by
        #3

        Hi, How about... declare @value varchar(11) set @value = cast(12345678 as varchar) select cast(substring(stuff(@value, len(@value)-1, 0, substring(@value,1,1)), 2, len(@value)) as int) Ryan

        A 1 Reply Last reply
        0
        • R RyanEK

          Hi, How about... declare @value varchar(11) set @value = cast(12345678 as varchar) select cast(substring(stuff(@value, len(@value)-1, 0, substring(@value,1,1)), 2, len(@value)) as int) Ryan

          A Offline
          A Offline
          ac011
          wrote on last edited by
          #4

          Thanks very much

          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