Solved

Deleting Characters from sql column

Posted on 2013-06-17
2
370 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
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now