Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Insert a character in a string Expand / Collapse
Author
Message
Posted Monday, July 30, 2012 10:37 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 6:31 AM
Points: 100, Visits: 332
Good afternoon,

I have part numbers that begin as RA99999-99. I need to update them all to read RA099999-99. Thanks for any help.
Post #1337392
Posted Monday, July 30, 2012 10:40 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 9:03 PM
Points: 2,262, Visits: 5,405
Will always the first two characters be alphabets ? and will it always be two characters?
Post #1337395
Posted Monday, July 30, 2012 10:41 AM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Yesterday @ 4:15 PM
Points: 694, Visits: 5,946
I think the STUFF function is what you are looking for.

declare @txt varchar(20) = 'RA99999-99'

select STUFF(@txt, 3, 0, '0')

Post #1337396
Posted Monday, July 30, 2012 10:41 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 9:03 PM
Points: 2,262, Visits: 5,405
Try

SELECT STUFF ('RA99999-09',3,0,'0')

Post #1337398
Posted Monday, July 30, 2012 10:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 6:31 AM
Points: 100, Visits: 332
The first characters will always be letters.
Post #1337412
Posted Monday, July 30, 2012 10:29 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:11 AM
Points: 36,995, Visits: 31,516
kabaari (7/30/2012)
The first characters will always be letters.

I guess the best way to ask the question is "Do you always want the extra "0" to be inserted into the 3rd character position?" If so, then the STUFF methods listed before this will do the job. If not, post back with some additional details.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1337659
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse