LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Querying a database for values in each row

In database terms, you want to LEFT JOIN all the rows in your Excel
range (table on the left) to those in the your external database
(table on the right) or a row of nulls if there is no match. The join
would look something like this:

SELECT T1.Col1, T1.Col2, T1.Col3, T2.LookupCol As NewCol
FROM MyExcelData T1 LEFT JOIN
MyExternalData T2 ON T1.Col1=T2.Col1
AND T1.Col2=T2.Col2
AND T1.Col3=T2.Col3

I've never known a RDBMS allow you to JOIN tables from different data
sources on the fly i.e. without previously linking servers (SQL
Server) or using linked tables (MS Access). You need both tables in
the same 'place'.

Also, in database terms, you are talking about appending a new column
to an existing table, which is not something normally done on the fly
with a query!

So it makes me wonder: is this a one off or something you will be
doing regularly in an Excel application?

If it's a one off, you are probably best off importing or linking the
Excel data within the RDBMS, create a new table locally using a LEFT
JOIN, then updating the original Excel source. If it was a regular
thing, it would be difficult to do all this in code from Excel if you
wanted to repeat regularly.

Post back with some more details e.g. the external database (MS
Access, SQL Server, another Excel workbook etc), what your data looks
like (Excel and external), how often you plan to do this, whether to
run from code, etc.

--

"Stephen Goldfinger" wrote in message ...
Howdy.

I have a worksheet where each row has several columns with
values. I want to take these column values and look up a
value from an external database. I also don't want to
create a query for each row (since there are many
thousands of rows). I know how to get a query to return a
value for a single row, but is there a way to get a query
to return a value for each row and place the result in a
column at the end of the row whose values are being
matched.

Thanks in advance for your help.

Stephen

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Querying Large Database RussellT Excel Discussion (Misc queries) 0 November 2nd 09 07:46 PM
Summing values in a database against certain criteria Bella Gray Excel Worksheet Functions 1 June 2nd 08 12:32 PM
SUMIF positive values only from database gmac Excel Worksheet Functions 4 June 29th 05 09:51 AM
How to aggregate values in a database Frank Excel Worksheet Functions 0 March 16th 05 01:15 PM
Querying Access Database Edgar Thoemmes Excel Worksheet Functions 1 December 15th 04 01:58 PM


All times are GMT +1. The time now is 06:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"