Query multiple tables from a master list of tables

I am working on a project where data from a large number of cells (5,000 +/-) from an Excel spreadsheet are read and stored in several tables. There is a table in the DB that has a row for each Excel cell that is read. This table (let's call it ExceltoSQLMap) basically maps the Excel Worksheet and Cell to the DB Table and Field where the Excel data is stored.

I was able to write a fairly simple stored procedure to return the value from any given table/column. In the stored procedure, I build a string from input parameters that looks something like: 'Select ' + @FieldName + ' FROM ' + @TableName.

I am calling the Stored Procedure from VB code. It works fine, but it takes something like 3 minutes to iterate over all 5,000 fields. There must be a way to generate the dataset from within a stored procedure, but I can't conceptualize how to do this.

The table ExceltoSQLMap from above has columns for TableName and ColumnName. So I started with a select statement that looked like: SELECT TableName,FieldName FROM ExceltoSQLMap. Now what do I do to join the actual tables where the data is stored?

Any help or thoughts would be appreciated

more ▼

asked Apr 04, 2010 at 09:02 PM in Default

avatar image

1 1 1 1

it will help us to better understand your requirement, if you can edit your post and add in your table structure, sample data and required result

Apr 04, 2010 at 10:11 PM Squirrel 1
(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Apr 04, 2010 at 09:02 PM

Seen: 1319 times

Last Updated: Apr 04, 2010 at 09:02 PM

Copyright 2017 Redgate Software. Privacy Policy