Solved

SQL commnad

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

11 Experts available now in Live!

Get 1:1 Help Now