I'm having some problems with Temp Tables (see that message), but as long as
I'm asking for ideas, perhaps there is a way to do this in SQL that I may be
overlooking. I am trying to perform a join between a master table and a
related table, where there may be multiple matching records in the related
table. What I want is the "best available" record from the related table
for the join. For example the master has: Keyfield, Other Data. The
related table has Keyfield, DataLevel, & Other Data, where DataLevel might
be an integer and the lower the value the more preferred the record. My
select looks something like:
SELECT m.Keyfield, r.DataLevel, m.aa, r.bb, r.cc FROM master AS m INNER JOIN
related AS r ORDER BY m.Keyfield, r.DataLevel
Since there is a one-many relationship between the tables, I'm getting 1 or
more matches per Master record. I only want the first matching record for
each KeyField however, the one with the lowest DataLevel value. Is there a
way to code this in SQL such that I can get just that one record without
having to get them all, then step through the recordset with procedural
code? Also, the queries involved in the query have to be dynamically
created, so I won't be able to use a stored procedure
Thanks very much for any help,
-- Greg
Semper Software, Inc.
www.SemperSoft.com