Solved

SQL commnad

Posted on 2009-05-20
1
159 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
1 Comment
 
LVL 41

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

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

12 Experts available now in Live!

Get 1:1 Help Now