SQL Server Performance

Using Stuff but from the right

Discussion in 'General Developer Questions' started by Raulie, Apr 7, 2004.

  1. Raulie New Member

    SELECT STUFF(Prov_RFC,4, 1, '-')

    How can I use this same formula but to insert the dash from e characters from the right. I need to convert "AAA123456BBB" into "AAA-123456-BBB". I cant use SELECT STUFF(Prov_RFC,11, 1, '-') becuase the number values in the middle could have 4 - 6 digits thats why I want to take tha last three digits from the right.

  2. ChrisFretwell New Member

    How about this? (no stuffing involved)

    select left(prov_rfc,3) + '-' + substring(prov_rfc,4,len(prov_rfc)-6) + '' + right(prov_rfc,3)

    If I did this right, then len(prov_rfc)-6 would the total length less the first 3 and last three characters, leaving how many are in the middle.

  3. Raulie New Member

    Thanks I will play around with this.

Share This Page