declare @position int
declare @string varchar(2000)
set @string = 'American Baby|BabyTalk|CTU|CordTrust|Gerber Life|BOTM Club|Career_Institute|Fast Lane|FinancialMatch|Kabeep|Aricept_PD|CBOTMC_TIB|Arca_Recipe_RP|FCR|Columbia|TruGreen_Rex|CHJ_Ziploc_RetPath|Terminix_MedWhiz|ScienceFiction_PD|Cosmetique_Rex|PerfectDiet_rex|QuickRewards|WomensDebt|NewCar_Innov|Maxima_PD|MyWireless_PD|Encore|'
set @position = 5
;WITH StringBreaker(Pos, Ordinal)as
(SELECT Number, ROW_NUMBER() OVER (ORDER BY Number)
FROM dbo.Numbers
WHERE SUBSTRING(@string, Number, 1) = '|')
SELECT Pos
FROM StringBreaker
WHERE Ordinal = @position;
Requires a Numbers table (Tally table to some people).
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon