Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select Part of string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-14 : 07:18:18
Thufail Ahmed writes "consider a table having column "id", values are like
012-mark-china
0116-peter-germany
099-smith-Africa

and so on....

How to retrive only the middle part like mark,peter,smith and disply it in sorted form... using a single query..."

gpl
Posting Yak Master

195 Posts

Posted - 2004-06-14 : 07:44:43
See this brilliant article http://www.sqlteam.com/item.asp?ItemID=15044

Select PARSENAME(Replace(ID, '-', '.'),2) from <table>

Graham
Go to Top of Page

JasonGoff
Posting Yak Master

158 Posts

Posted - 2004-06-14 : 07:48:26
select SUBSTRING(id,CHARINDEX('-',id)+1,LEN(id)-CHARINDEX('-',id,CHARINDEX('-',id)+1)-1)
Go to Top of Page

JasonGoff
Posting Yak Master

158 Posts

Posted - 2004-06-14 : 07:54:00
quote:
Originally posted by gpl

See this brilliant article http://www.sqlteam.com/item.asp?ItemID=15044

Select PARSENAME(Replace(ID, '-', '.'),2) from <table>

Graham



Now that is FAR more elegant than my approach. You learn something new every day. Thanks Graham !
Go to Top of Page
   

- Advertisement -