Solved

SQL commnad

Posted on 2009-05-20
1
167 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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

823 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