Solved

Deleting Characters from sql column

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

688 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