Re: Using LIKE in a JOIN

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Jason,

I'll have to try it out, thanks. Even if it doesn't work, you helped me
learn something. I wasn't aware you could call a function from a query. I
might play with that a bit more.

Currently, I edited my upload routine to perform the same actions as your
function and added another column to Table1.

Now it'll be stored in the DB. Not a perfect solution, but it seems to work.

Thanks again,
Jay

"Jason Lepack" wrote:

I wrote this function, paste it into a module and save the module to be
able to use it:
Public Function getNumber(s As String) As Long
Dim x As String
x = s
Do While Not IsNumeric(x)
x = Mid(x, 2)
Loop
getNumber = CLng(x)
End Function

I used this query: (Table 1 and Query 1 are from your definitions in
your original post)
SELECT A.*, B.Creator
FROM (SELECT *, getNumber([REPORT_NUM]) AS X FROM [Table 1]) AS A
INNER JOIN [Query 1] AS B
ON A.X = B.RPT

It may be a bit slow but it will work. See what you think.

Cheers,
Jason Lepack

Jay wrote:
Yeah, Jason's post pointed out the error in my thinking.

What I think the better option will be is to strip the characters from the
beginning of the value and convert to int. Therefore:
RT00029 --> 00029 --> 29
RTP00029 --> 00029 --> 29
RTP00129 --> 00129 --> 129
RT00129 --> 00129 --> 129

The only 'consistent' aspect of the REPORT_NUM is the format is any number
of characters followed by any number of digits. No digits between characters
(or vice versa).

I'm beginning to believe this is too complicated for a SELECT statement.

"John Vinson" wrote:

On Tue, 23 Jan 2007 09:01:00 -0800, Jay
<Jay@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

The problem is, the prefix of REPORT_NUM won't be consistent. That's why I
want to do a substring search within REPORT_NUM, looking for a RPT that's
within it. And I can't make it consistent. The data comes from a separate
system which I can't control.

So it can be ANYWHERE!?

What would you do with a REPORT_NUM of

RPT034730

That contains 34, 47, 73, and 30 - which is the desired substring?

Garbage in, garbage out, I fear!!

Your *examples* all have the creator code as the rightmost two
characters: can you at least count on that? If so,

SELECT <whatever fields from Table1>, Table2.Creator
FROM Table1 INNER JOIN Table2
ON Table2.RPT = Right(Table1.Report_Num, 2);

But if you can't ascertain WHICH two digits in the field provide the
link I think you're out of luck.

John W. Vinson[MVP]



.



Relevant Pages

  • Re: Field Automatically
    ... I would like my query to Look at the last for digits of ... I want my query to go ... When you use the word join tables and make a ... >> other table is 4 characters long. ...
    (microsoft.public.access.queries)
  • Re: splitting a number
    ... Use an Update query to populate ... Use Rightto parse the right 2 characters. ... To remove the last 2 digits from the field, ...
    (microsoft.public.access.queries)
  • Re: How to search for inappropriate characters?
    ... You might use criteria on your phone number field like this: ... in query to return the records where the phone number field contains ... characters that are not digits. ...
    (microsoft.public.access.queries)
  • Re: how to get last records out of 4 records per customer?
    ... Some how my query is failing at WHERE Dupe.CustomerID = Table1.CustomerID ... of those characters. ... FROM Table1 AS Dupe ...
    (microsoft.public.access.queries)
  • Re: Truncated Memo field displayed on form
    ... 255 characters in any column that is in the combo box's RowSource query. ... My fields down to "Knowledge and Understandings" are fine. ... occurs with the "descriptor" field being truncated on my form. ...
    (microsoft.public.access.forms)