Monday, March 26, 2012

Need SQL statement help!

Hello everyone,
I need help with two SQL statements
The first is:
I have a table called tbSitters which contains two columns named
bsLastName and bsAboutMe. I want to be able to find records where the
value stored in bsLastName can be found in bsAboutMe for a single row
(not all records) bsAboutMe is a text field which may contain up to 50
words or more.
The second is:
I have a table called tbPcodes which has two columns named bsID and
pcMyZips. I want to be able to bring up any duplicates in pcMyZips,
which are associated to bsID. For example:
bsID pcMyZips
001 100
001 100
001 101
001 102
002 201
002 202
002 203
002 204
It would return bsID 001 because there is a duplicate entry(100) in
pcMyZips.
Any help would be greatly appreciated!
Thanks Robert> The first is:
> I have a table called tbSitters which contains two columns named
> bsLastName and bsAboutMe. I want to be able to find records where the
> value stored in bsLastName can be found in bsAboutMe for a single row
> (not all records) bsAboutMe is a text field which may contain up to 50
> words or more.

> The second is:
> I have a table called tbPcodes which has two columns named bsID and
> pcMyZips. I want to be able to bring up any duplicates in pcMyZips,
> which are associated to bsID. For example:
> bsID pcMyZips
> 001 100
> 001 100
> 001 101
> 001 102
> 002 201
> 002 202
> 002 203
> 002 204
>
For the first one try:
SELECT * FROM tbSitters
WHERE bsAboutMe LIKE '%' + bsLastName + '%'
For the second one try:
SELECT bsID, pcMyZips, COUNT(pcMyZips)
FROM pcMyZips
GROUP BY bsID, pcMyZips
HAVING COUNT(pcMyZips) > 1
Rick Sawtell|||Hi Rick,
Thans for the reply!
The second statement works perfect.
The problems I'm having with the results of the first statement, is
some members only enter in their intial in the bsLastName field, so a
lot of results are being returned. Would it be possible to specify that
there must be a blank space before and after when matching the text
values? This would eliminate a lot of the false returns.
Or, If that's not possible, could the statement be altered to include
bsLastName('s) which are a minimum of 3 characters long only?
Much appreciated Rick,
Thanks, Rob|||ROBinBRAMPTON wrote:

> Would it be possible to specify
> that there must be a blank space before and after when matching the
> text values? This would eliminate a lot of the false returns.
Try SELECT * FROM tbSitters
WHERE bsAboutMe LIKE '% ' + bsLastName + ' %'
HTH,
Stijn Verrept.

No comments:

Post a Comment