?
Solved

Deleting Characters from sql column

Posted on 2013-06-17
2
Medium Priority
?
381 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

801 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