Re: Group newbie: question on parsing a field value > Is there an SQL function I could use that would strip away everything but
> the text following the last period? I could then easily do the same in the
> ASP script and compare integers. Something like:
>
> This also needs to work in MS Access BTW :-)
Hi,
I don't know anything about Access. You can use a table of numbers
trick to parse your "node" into individual nodes by using the period
as a delimiter. Erland has documented it in his site. In the code
below, I called my table of numbers TALLY which has one column ID with
values from 1,2,3,... to 8000.
declare @node varchar (50)
set @node='1.2.10'
SELECT
substring(phrase,s,(e-s-1)) as NODES
FROM
(
SELECT
id,
phrase,
charindex('.','.'+phrase+'.',id) as s,
charindex('.','.'+phrase+'.',id+1) as e
FROM tally,(select phrase=@node) A
WHERE charindex('.','.'+phrase+'.',id) <
charindex('.','.'+phrase+'.',id+1)
) B
OUTPUTS:
NODES
--------------------------------------------------
1
2
10
Further modifying it to output the last NODE piece:
SELECT
substring(phrase,s,(e-s-1)) as NODES, identity(int,1,1) as i
INTO #T
FROM
(
SELECT
id,
phrase,
charindex('.','.'+phrase+'.',id) as s,
charindex('.','.'+phrase+'.',id+1) as e
FROM tally,(select phrase=@node) A
WHERE charindex('.','.'+phrase+'.',id) <
charindex('.','.'+phrase+'.',id+1)
) B
SELECT NODES FROM #T WHERE i=(SELECT max(i) as i FROM #T)
OUTPUTS:
NODES
--------------------------------------------------
10 |