Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Query SQL Server

I have an Excel sheet with 3 columns: PartNo, Cost and Price.

The PartNo column contains values that a user has entered. The other 2
columns (Cost and Price) contain no values currently.
I would like to populate the Cost and Price columns with values from a SQL
database using the value in the PartNo column.

I am guessing that I will loop through the PartNo column and query the
database for each PartNo to obtain the Cost and Price.

How can I retrieve values from the database and place those returned values
in their respective columns? Is there a way to perform the query and have
the results of the query stored in a variable?

I would rather place just the value in the respective column and not have
any "link". I have tried SQL.REQUEST which worked, but I am not crazy about
the fact that it refreshes automatically.

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Query SQL Server

Hello Kevin:
The other problem with SQL.REQUEST is that it needs to connect, process, and
disconnect each time it calculates.
What you really need to do is use an ADO disconnected recordset in VBA. If
you are not familiar, ADO=ActiveX Data Objects and provides an object model
for working with external data sources. You create a connection to your SQL
database, create a recordset based on an SQL query, and then close the
connection while saving the recordset (and the query results). If the
recordset is saved as a Public object variable, it can be used in a user
function you could write to find specific data (i.e. to match your Part Nos).

Too much to go into here, but you can check out the MSDN library. Here's a
start (and then try a search for "ADO disconnected recordset")
http://msdn.microsoft.com/library/de...entid=28001860

"Kevin L" wrote:

I have an Excel sheet with 3 columns: PartNo, Cost and Price.

The PartNo column contains values that a user has entered. The other 2
columns (Cost and Price) contain no values currently.
I would like to populate the Cost and Price columns with values from a SQL
database using the value in the PartNo column.

I am guessing that I will loop through the PartNo column and query the
database for each PartNo to obtain the Cost and Price.

How can I retrieve values from the database and place those returned values
in their respective columns? Is there a way to perform the query and have
the results of the query stored in a variable?

I would rather place just the value in the respective column and not have
any "link". I have tried SQL.REQUEST which worked, but I am not crazy about
the fact that it refreshes automatically.

Thanks



Reply
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
Change Server for Query Cinco Excel Discussion (Misc queries) 3 July 31st 09 01:04 AM
Excel with SQL Query (*.sql) and SQL Server Kode Excel Discussion (Misc queries) 2 May 8th 07 01:10 PM
Query SQL Server from Excel Doctorjones_md Excel Discussion (Misc queries) 1 January 6th 07 08:35 AM
Query SQL Server from Excel Doctorjones_md Excel Worksheet Functions 1 January 6th 07 08:35 AM
How do I run a SQL query against a MS SQL Server database from exc DPL Excel Discussion (Misc queries) 0 February 8th 05 07:33 PM


All times are GMT +1. The time now is 10:15 PM.

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

About Us

"It's about Microsoft Excel"