FW: [AccessD] SQL to count delimiters in a string

Hale, Jim Jim.Hale at FleetPride.com
Wed Aug 24 13:16:09 CDT 2005


This looks interesting. I'll give it a try, thanks
Jim Hale

-----Original Message-----
From: catchrest at denverdb.com [mailto:catchrest at denverdb.com]
Sent: Wednesday, August 24, 2005 11:25 AM
To: Jim.Hale at fleetpride.com
Subject: Re: [AccessD] SQL to count delimiters in a string


Jim,

Please feel free to post this to the group, my webmail does not work with
the 
proper Reply To Settings.  This SQl will get you what you want, I would 
convert it to a Function, but here's the code:


DECLARE @str	VarChar(500)
DECLARE @x INT
DECLARE @Count INT

SET @str = 'st|ddd|ww|ex 3 fff|sss 1 eenie|meenie|minie|moe 3'

SET @x = CharIndex('|', @str,  1)
SET @Count = 0
WHILE @x <> 0
BEGIN
	SET @Count = @Count + 1
	SET @str = SubString(@str, @x + 1, 500)
	SET @x = CharIndex('|', @str)
END

PRINT @Count

-- Chris Mackin
> 
> Assume I have a text field in a table. Further assume 
> that the text strings
> are delimited by the pipe chara
> cter "|". I want to know how many pipe
> characters occ
> ur in each field, ie. the select statement should retu
> rn:
> 
> fldText                         Occurrences
> te
> st|ddd|ww|ex                3
> fff|sss                
>              1
> eenie|meenie|minie|moe   3
> 
> What is 
> the correct SQL to produce the desired result? TIA
> Ji
> m Hale
> 
> ********************************************
> ***************************
> The information transmitt
> ed is intended solely for the individual or
> entity to
>  which it is addressed and may contain confidential an
> d/or
> privileged material. Any review, retransmission,
>  dissemination or
> other use of or taking action in re
> liance upon this information by
> persons or entities o
> ther than the intended recipient is prohibited.
> If yo
> u have received this email in error please contact the
>  sender and
> delete the material from any computer. As
>  a recipient of this email,
> you are responsible for s
> creening its contents and the contents of any
> attachm
> ents for the presence of viruses. No liability is acce
> pted for
> any damages caused by any virus transmitted 
> by this email.
> 
> 
> 
> 
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 
> 

______________________________________
This E-Mail was sent with MailMax/WEB.
http://www.smartmax.com



***********************************************************************
The information transmitted is intended solely for the individual or
entity to which it is addressed and may contain confidential and/or
privileged material. Any review, retransmission, dissemination or
other use of or taking action in reliance upon this information by
persons or entities other than the intended recipient is prohibited.
If you have received this email in error please contact the sender and
delete the material from any computer. As a recipient of this email,
you are responsible for screening its contents and the contents of any
attachments for the presence of viruses. No liability is accepted for
any damages caused by any virus transmitted by this email.


More information about the AccessD mailing list