Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Posts
    1

    Unanswered: Replacing one part of a number

    I need to change the first digit (0) in a number, like 05678494 and replace it with 0046 so it would look like 00465678494 when it is done.
    I have tried to use the REPLACE function without any success.
    Can anyone help me?

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    What datatype is your value?

    What about this:

    REPLACE('X' + YOURNUM, 'X0', '0046')
    Last edited by blindman; 12-01-04 at 12:45.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Well, first it's not really a number

    Second, If you have any "congac" strings * any where else in the string, they'll get replaced as well...

    Third, if it always the first 0, then

    Code:
    DECLARE @x varchar(20)
    SELECT @x = '05678494'
    SELECT @x = CASE WHEN SUBSTRING(@x,1,1)= 0 THEN '0046' + SUBSTRING(@x,2,LEN(@x)-1) ELSE @x END
    SELECT @x
    Should do it


    * (X0)
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    congac?

    I thought you were a margarita drinker?
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    You brought up the X0

    I had X0 once...believe it was Remy..smoooooooooth

    And I'm an equal opportunity patron....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •