Solved

Deleting Characters from sql column

Posted on 2013-06-17
2
377 Views
Last Modified: 2013-06-17
Hi I need to do a script in which will take characters off of a string for example:

if i have 1234-56/protrac i need to keep the 1234-56 and just delete the /protrac. so how can I do a script in which will constantly just remove the last 8 characters???

Your help is much appreciated. I know how to make it take off the last characters like this:

update ssfields
set
Field1 = SUBSTRING(field1, 1, 7)


but i am unsure that it will always be a 7 character number. So I need something that will automatically remove the / and the characters after it.
0
Comment
Question by:psmittyy14
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Simone B earned 500 total points
ID: 39253568
You can use CHARINDEX to find the location of the first occurrence of the slash, then subtract one to get the length of the substring.

update ssfields
set
Field1 = SUBSTRING(field1, 1, CHARINDEX('/', field1)-1)
0
 

Author Comment

by:psmittyy14
ID: 39253573
Thank you so much!!! That is perfect!
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question