Solved

sql FIELD CONVERT (SHORTEN)

Posted on 2011-09-14
3
300 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
[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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

691 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