Solved

Deleting Characters from sql column

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
best counters for cpu high usage 3 33
Tsql query 6 22
Syntax for query to update table 2 15
SQL Server syntax 4 23
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

832 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