Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rwsjbs
Starting Member
17 Posts |
Posted - 2008-02-10 : 15:47:05
|
We store an item’s barcode number in an SQL table named ProductNumber. The field we store the number in is called Number. Currently we are using all 12 digits on the barcode. We are switching to only use the 10 digits in the middle of the barcode. So, I’m trying to:1. Update all numbers in field ProductNumber.Number that are 12 digits2. Then trim off the 1st digit and the last (12th) digit3. So, this leaves me with the 10 middle digitsHere is an example:Currently the number is:710817117329I need it be updated to1081711732I would appreciate if someone could show me the correct SQL statement to select the numbers that equal 12 and delete the 1st and 12th digit leaving me with 10 digits.Thank you! |
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2008-02-10 : 15:54:37
|
Update ProductNumberSet Number = substring (Number,2,10)Where len(RTRIM(LTRIM(Number)) = 12You don't need replace, you need substring. Poor planning on your part does not constitute an emergency on my part. |
 |
|
rwsjbs
Starting Member
17 Posts |
Posted - 2008-02-11 : 08:51:32
|
Thank you for the quick reply. I really appreciate your help. |
 |
|
rwsjbs
Starting Member
17 Posts |
Posted - 2008-02-11 : 09:22:17
|
We added a ) to the last line and it works great! Thanks so much for sending us the sql statements. You saved us a considerable amount of time. |
 |
|
|
|
|