Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

RE: FN-FORUM: One for the SQL Experts

date posted 11th September 2007 08:45

Craig wrote:
> Hi,
>
> There is a tblMailingList.mailingGroupID field that has recently been
> converted to hold a comma delimited list of mailingGroupID's. I need
> to add something to this query to say "AND the supplied number exists
> in mailingGroupID" but in SQL of course. In other words, if the
> mailingGroupID field holds: 5,2,6,8,2 and the supplied number is 2
> then I want it included in the count.

Firstly the obligatory pedagogic advice - don't store multiple values in one
column like this...ever. It may seem like hard work to create a separate
table but in any halfway normal scenario where the site will continue to be
used and developed it will be less work and certainly less pain in the long
run. Even now that ship has sailed I would seriously consider going back
and reworking it with the extra table.

Assuming you don't do that, your best bet is to use a delimiter and ensure
it goes at _both_ ends of the data e.g.

,1,11,11,12,2,21,

Then you can search explicitly for "," & Number & "," which avoids false
matches on partial numbers.

If for any reason you can't even change the way it is stored, you can
probably do it with a regexp search along the lines of

"(,|^)" & Number & "(,|$)"

Which is to say the number with either a comma or the beginning of the data
before it and either a comma or the end of the data after it.

HTH,

Dai



Messages by Day
September 30th 2007
September 29th 2007
September 28th 2007
September 27th 2007
September 26th 2007
September 25th 2007
September 24th 2007
September 23rd 2007
September 22nd 2007
September 21st 2007
September 20th 2007
September 19th 2007
September 18th 2007
September 17th 2007
September 16th 2007
September 15th 2007
September 14th 2007
September 13th 2007
September 12th 2007
September 11th 2007
September 10th 2007
September 9th 2007
September 8th 2007
September 7th 2007
September 6th 2007
September 5th 2007
September 4th 2007
September 3rd 2007
September 2nd 2007
September 1st 2007


Messages by Month
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000