Solved

SQL query to retun only part of a piece of data

Posted on 2011-03-08
3
239 Views
Last Modified: 2012-05-11
I have a table in a database that contains data that looks like this:

10-25-665-123456
10-25-666-123548

The format of the data is always the same number of digits with the dashes always in the same place.  I am looking for a query that will only return certain parts of the data.  For example, I want the query to return only the first two digits, then then next two digits, then the next digits and so on so that my result from the query would contain separate columns with each of those pieces of data that is separated by the dashes.  Is this possible?  I know you can probably somehow use the Replace command but not sure how.
0
Comment
Question by:jwmillerill
[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 9

Accepted Solution

by:
rajeevnandanmishra earned 125 total points
ID: 35072890
Hi,
You can use the substring command.
Like:
SELECT SUBSTRING(myColumn,1,2) col1, SUBSTRING(myColumn,4,2) col2, SUBSTRING(myColumn,7,2) col3,
             SUBSTRING(myColumn,11,6) col4
FROM myTable
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35072894


SELECT SUBSTRING('10-25-665-123456', 1, 2) 'Part1',
       SUBSTRING('10-25-665-123456', 4, 2) 'Part2',
       SUBSTRING('10-25-665-123456', 7, 3) 'Part3',
       SUBSTRING('10-25-665-123456', 11, 6) 'Part4'
0
 
LVL 1

Author Closing Comment

by:jwmillerill
ID: 35072931
Brilliant.  Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

734 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