Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Update part of a field in SQL Server

I have a column with fields that containt 10 digit numbers and conditions, such as 'Very Good', or 'Acceptable'. (Field is named Sku). How would I got about updating the field so that I left the 10 digit numbers intact but replaced the words ex. 'Very Good' with 'VG'. I also want to eliminate any spaces between the digits and the words so 0123456789 Very Good would become 0123456789VG. FYI, the 10 digit number always comes first in the field. Thank you.
0
bpfsr
Asked:
bpfsr
  • 3
  • 2
2 Solutions
 
Daniel WilsonCommented:
update MyTable set SKU = Replace(Replace(SKU, 'Very good', 'VG'), ' VG', 'VG')
0
 
bpfsrAuthor Commented:
Daniel,
Thank you. If you don't mind, can you explain the logic just so I get a better understanding, thanks.
0
 
Kevin CrossChief Technology OfficerCommented:
What Daniel is showing is updating the field with same value currently in that field but using the REPLACE function to change instance(s) of 'Very good' with 'VG'.  Then in a second replace change ' VG' to 'VG'.

So in terms of your data, it is doing this in the two steps:

1>0123456789 Very Good --> 0123456789 VG
2>0123456789 VG --> 0123456789VG
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Kevin CrossChief Technology OfficerCommented:
0
 
Daniel WilsonCommented:
Thanks for the followup & explanation, Kevin.
0
 
Kevin CrossChief Technology OfficerCommented:
Hopefully I did your answer justice. :)
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now