Solved

SQL commnad

Posted on 2009-05-20
1
189 Views
Last Modified: 2012-05-07
HI,

I have column in sql server 2005 which contain the following format of data.

01.20.30.16
02.30.60.189 etc.

Four parts of digits seperated by a period. How can I select each part seperate?

ayha
0
Comment
Question by:ayha1999
[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
1 Comment
 
LVL 42

Accepted Solution

by:
pcelba earned 30 total points
ID: 24433313
The following code does it for you, you just have to provide column name
SELECT LEFT(YourCol, CHARINDEX('.', YourCol)-1) as part1,
       SUBSTRING(YourCol, CHARINDEX('.',YourCol)+1, CHARINDEX('.',YourCol,CHARINDEX('.',YourCol)+1)-CHARINDEX('.',YourCol)-1) as Part2,
       REVERSE(SUBSTRING(REVERSE(YourCol), CHARINDEX('.',REVERSE(YourCol))+1, CHARINDEX('.',REVERSE(YourCol),CHARINDEX('.',REVERSE(YourCol))+1)-CHARINDEX('.',REVERSE(YourCol))-1)) as Part3,
       RIGHT(RTRIM(YourCol), CHARINDEX('.',REVERSE(RTRIM(YourCol)))-1) as Part4
FROM YourTable

Open in new window

0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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