Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    20

    Question Unanswered: concatenation but with a format...

    Hi Consider a table with a decimal and a string varibale.

    Dec String
    3 fred
    23 bill

    I need to concatenate them but with leading zeros such as
    03Fred
    23Bill

    Ideas please ??

    Gerry

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    As long as you don't need to cope with negative numbers, you can get by with the simple solution of:
    PHP Code:
    SELECT Replace(Str([Dec], 2), ' ''0')
       
    FROM dbo.myTable 
    -PatP

  3. #3
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    drop table #tmp
    create table #tmp(id int,col1 varchar(10))
    go
    insert #tmp(id,col1) values(1,'a')
    insert #tmp(id,col1) values(11,'b')
    insert #tmp(id,col1) values(111,'c')
    insert #tmp(id,col1) values(1111,'d')
    insert #tmp(id,col1) values(11111,'e')
    insert #tmp(id,col1) values(23,'f')
    go
    select replicate('0',5-len(cast(id as varchar)))+cast(id as varchar)+' '+col1 from #tmp

  4. #4
    Join Date
    Mar 2004
    Posts
    20
    Both worked nicely. Thanks a lot

    Gerry

Posting Permissions

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