Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Unanswered: Concatenate A String to another String

    Good Afternoon All,

    I would like some help in appending or concatenate a string to another string with the following code:

    Code:
    declare @trans_date smalldatetime, @trans_date_c varchar(12)
    
    select @trans_date='10/06/2010'
    
    select @trans_date_c=convert(varchar(12),@trans_date,101) --need to make char(8) and remove slashes
    
     
    
    /* 300 - position 10 len 3
    
       Date - position 16 len 8 -- remove slashes MMDDYYYY
    
       Amount - position 74 len 11  -padded with zeros on the left, decimal implied
    
       Voucher ID - position 127 len 8 -left justified with spaces on right
    
     */   
    
    select '1' + replicate(" ", 8)+'300'+
    
    replicate(" ", 3)+str_replace(@trans_date_c,'/',null)+ 
    
    replicate(" ", 50)+replicate("0",11-char_length(str_replace(convert(varchar(11),sum(fee_due)),'.',null))) + 
    
    str_replace(convert(varchar(11),sum(fee_due)),'.',null)+ 
    
    replicate(" ", 42)+
    
    convert(varchar(8),isnull(r.voucher_id, r.remittance_id)) 
    
     +replicate(" ",8 char_length(convert(varchar(8),isnull(r.voucher_id, r.remittance_id)))) + replicate(" ",10) /*HERE IS WHERE I WANT TO INSERT "PGC" BEFORE THE CHAR STRING/*
    For the code highlighted in blue, I would like to concatenate (or append) "PGC" directly before the eight char string. So the new converted string should appear as PGC01234567

    I have tried the code below, but it is not working. What I am doing wrong?

    Code:
     replicate("PGC", 1(replicate(" ",8-char_length(convert(varchar(8),isnull(r.voucher_id, r.remittance_id)))))

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Why have
    replicate("PGC",...
    Maybe you want
    "PGC"+replicate(" ",8 ...

  3. #3
    Join Date
    Oct 2010
    Posts
    2
    Thanks!! That worked great.

    This issue has been resolved

Posting Permissions

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