Solved

sql FIELD CONVERT (SHORTEN)

Posted on 2011-09-14
3
296 Views
Last Modified: 2012-05-12
THIS IS PROBABLY SUPER EASY FOR ALL OF YOU.. BUT I'M STILL A NEWBIE AT SQL

i HAVE A COLUMN THAT CONTAINS DATA THAT LOOKS LIKE THIS.

666/WK22Reynolds/Jun 03, 2011/74/1/  

1057/6182011ims/Jun 22, 2011/302/1/1/ 1096-/217000-  -/3

I WANT TO CHANGE IT TO ONLY USE THE THE NUMBERS UP TO THE FIRST '/'

THEREFORE: return would be  

666  
1057
Can you help please?
0
Comment
Question by:Cree
3 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 250 total points
ID: 36537185
SELECT SUBSTRING(Field1, 1,patindex('%/%',Field1)-1)
0
 
LVL 5

Expert Comment

by:zvytas
ID: 36537200
This will give you data you want, but as a string:

SELECT SUBSTRING(Column, 1, CHARINDEX('/', Column) - 1)

If you need an int, use the following:

SELECT CONVERT(int, SUBSTRING(Column, 1, CHARINDEX('/', Column) - 1))
0
 

Author Closing Comment

by:Cree
ID: 36537208
thanks.. you rock.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

920 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

17 Experts available now in Live!

Get 1:1 Help Now