How to search multiple table which table name is store in another table and join the result together?

I have one control table to store all related table name

 Table ID                   TableName

     1                           TableA

     2                           TableB


In Table A:

RecordID                Value

     1                         1

     2                         2

     3                         3


In Table B:

RecordID             Value

    1                         1

    2                         2

    3                         3

 How can I get the result by select the Table list first and then combine the data in table A and table B?


Thank you!

12/2/2006 12:22:28 AM 29906 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

I'm not sure exactly how you want to combine the data but I think you want to use dynamic sql.  The exec method takes a string and executes the sql statement

Let's say you are passing in a TableID and you want to get all the records of that table

DECLARE @TableID as int

SET @TableID = 1

DECLARE @TableName as varchar(50)

DECLARE @SQL as varchar(300)

SET @TableName = (Select TableName where TableID = @TableID)

SET @SQL = 'Select * from ' + @TableName



Community Coder
12/2/2006 4:12:35 PM

Similar Artilces:

Tables?! Why Tables?!
Bit random...but why does everything have to be rendered as a table?  It's starting to get quite annoying.  Formview - does this need to be a table?  the Menu??  Wouldn't it make sense to allow the option to...say...not render a Menu as a table?  Am I the only one that thinks this or are there others? You can use CSS Adapters to create your own adapters to override how the controls render it self. In the next version of ASP.Net, you will probably have more flexibility to specify the surrounding elements of th...

From Table to Table
I am working in Delphi 4 and ran into a roadblock I am unfamiliar with. I am trying to search and find values in one table based off of matching values in another. For example a table of objects with fields like name, description, type, ect; and a table of object properties in which each object can be represented multiple times based on the settings on the page at the time. So if i search the object property table (and eventually loop through to repeat for all objects) to find all cases of visible objects when a certain criteria is met. It stops on the first object with "Yes" in th...

SQL Query Problem - Joining a table to another table
 Ok i'm trying to build a sql query that pulls two names of users from 1 user table to matchup two users (instructor and teaching assistant) in the same record of another table but can't get it right.  Below is a simplified version of what i'm trying to do.  I have a table "Courses" that stores the ID of an Instructor and a Teaching Assistant assigned to the course.  Both the instructor name and teaching assistant name are pulled from the same table (as teaching assistants could technically be instructors as well).  The problem is i can't cr...

Table inside a Table results in a gap at the bottom of the table
All,When I put a table inside a table, it leaves a gap at the bottom.When you then have tables inside tables inside tables this gap becomes cumulative and are left with a hude gap at the bottome of the web form which is unwanted. Can anyone help. Cheers  Give height="100%" and width="100%" of inner table.Also check you had not given cellspacing and cellpadding with big value.BrindeshSoftware Developer,India.If you found that this is right answer then mark it as answer, so that future readers get benefits of it....

table splited into multiple tables, what's the procedure of updating multiple tables in GridView?
hello all, i have a 5-table normalized database, with primary keys and foreign keys ...and when i present the data using GridView, i use a VIEW the collects columns from all tables ...the problem is that, when using GridView & SqlDataSource, the SqlDataSource update command doesn't work because it has to update multiple i'm asking what's the right procedure when using normalized DB and GridView that make me enable editing and deletion built in GridView's capablities ?  thx all in advance. GLORY~Please mark as answer if this helps u~  use so...

getting user name from another table (id included in another table)
Hi,  I am using a datagrid and I have 2 tables (I will try to explain as simple as I can) ... First table contains SENDER_ID and TOPIC fields . The sender id's are the users Id's. Second table contains member records and Lets say it has it has MEMBER_ID , MEMBER_NAME columns. I get the values from first table to datagrid and I want the SENDER_ID 's to be converted to MEMBER_NAME 's  while displaying the data with datagrid . I am able to do this but I have to connect to db for every MEMBER_ID record to transform them to names .Here it is <ItemTemplate><%# ...

I am getting info from one table, CalibrationReview, that is not inanother table, tblEquipments. SELECT EquipmentNumber, Model, SerialNumber, Make, CalLabName, CalDateFROM CalibrationReviewWHERE NOT EXISTS (SELECT AssignedID FROM tblEquipments WHERE AssignedID = CalibrationReview.EquipmentNumber) Now, I need to take these rows and INSERT them into tblEquipments,but with some conditions. tblEquipments has some contraints, so, the following needs to be done: Using dbo.CalibrationReview.EquipmentNumber, get CalibrationMaster.TestTechnology where dbo.CalibrationReview.EquipmentNumber = dbo.C...

Inserting Multiple Records From A Table Into Another Table
I have a situation where I ran an query in ASP and displayed my data in a table.  Now I want to take that consolidated table and insert it into a different table.  How do I write the SQL query for that?  For the sake of the thread lets say the table is titled guests and the field I want to import are fname, lname and email   I have tried multiple ways and when I do something I get a single new record in the database, but all the fields are blank.   I really appreciate any assistance. you should loop through the consolidated table one row at a time and inse...

Reading from one table and then storing it into another table
I want to (and succeeded)  read information from one table in my database ([services] in this case) and display them in a table with an additional column with a textbox so that I can enter volumes in it. So far so good, this works fine. But I now want to store all the volumes together with the ID's in a seperate table ([service_volume]) by clicking the Submit button. Does anyone know how to achieve this?  <%@ Page Language="VB" %> <%@ Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "

How can i import records from a sql server table in project1 to another sql server table in project2
Hi, i have a table with all employee bio-data in a completed project. Iam now working on another project with a table that needs the same data and here iam talking about 300 records that rarely change. Instead of re-entering this data in this new table, i want to import the data from the completed project into a table in this new project. Does any one have any idea how to achieve that or is there a better option to do the same. One more thing iam realising here is that iam going to use this same data in very many applications and some one from one department is going to ...

Stored Procedure multiple table scan on large table
Hello, I have a problem Stored Procedure with a simple join on a small ( site ) and large table (financial booking ). How do I avoid a mutiple table scan on the large table ? Many thanks for any advise and suggestions Steve Adaptive Server Enterprise/ 9319 ROLLUP/ CREATE PROCEDURE ... ... IF ( (@claimid IS NULL) AND (@ip_tran_ref IS NOT NULL) ) BEGIN SELECT @home_dbid = s.dbid FROM site s, financial_booking f WHERE f.ip_tran_ref = @ip_tran_ref AND f.bk_source = 'SU' /* Rev 1.1 SteveH */ AND f.bk_ledger_site = s.s...

Updating another table using linq to sql table.
Hi,After successfully saved the values from the Rent Table, I want to update the Status attribute from "Available" to "On Booking" for that particular bike.The Status attribute is taken from the Bike Table.And I'm using linq to sql to save the values from the Rent Table.Here is how I save the Rent table without updating the "Status" attribute:  using (DataClassesDataContext context = new DataClassesDataContext()) { Rent rent = new Rent { NRIC = nrictxtbox.Text, Bikeid = Convert.ToInt32...

Insert multiple records from one table to another table
Hello. Got a quick problem. I need to post shopping cart items from a temperary table "ShopCart" to a permanent table "tbl_orders". Problem is, I cannot figure out how to iterate through the recordset to post the unique products from "ShopCart" to "tbl_orders". The code below inserts the first product-- but that's it. If there are 6 different products, it will insert the first product 6 times. Public Sub GetShopCart() Dim ordernumber = session("ordernumber") Dim objConn as new SqlConnection(strConn) Dim strSQL as Str...

Table JOINs with aspnet_ tables?
I'm building a web app and I'm thinking of using the new 2.0 membership features.I can create users and roles no problem.  I'd also like to link the user into into a separate table.Example:  Bob logs in.  Bob posts an article.  My article table should reference Bob's info.  Any thoughts on the best way to do that?Can I just create a UserId foreign key in my articles table that matches aspnet_Users.UserId and aspnet_Memberships.UserId?  If so, then can I just do some joins on those tables to get Bob's username and email?It seems like that would work but I'm inter...

Web resources about - How to search multiple table which table name is store in another table and join the result together? -

Eric Kingson Reflects On The Legacy Of Dr. Martin Luther King
The day after that speech, April 4, 1968, an earlier version of a prototypical Ted Cruz/Donald Trump/Mike Huckabee supporter shot and killed ...

Two top police body camera makers are locked in an epic patent battle
Two of the most prominent makers of body-worn cameras for cops and first responders are fightin' it out over patents.

VOTD: BB-8 Helps Industrial Light & Magic Accept Genius Award at Critics Choice Awards
Last night, the Critics Choice Awards were televised live for the first time ever. While the event wasn’t quite as star-studded as the Golden ...

Why It's Misleading to Say the 62 Richest People Have the Same Wealth As Half the World
Much of the money the global rich have does not exist on this planet. Tyler Olson/ shutterstock The story presently making the rounds in business ...

5 things to know about Flint's water crisis
CNN 5 things to know about Flint's water crisis CNN (CNN) An ongoing crisis in Flint is now drawing voluminous concern from around the nation ...

Spike Lee is Skipping the Oscars to Protest the All-White Nominations
Out of all the films and artists that were snubbed for Academy Awards nominations last week, one area of oversight stood out for being particularly ...

WhatsApp to drop renewal fees for the messaging service
WhatsApp, a popular mobile messaging service owned by Facebook, says it will drop its 99-cent subscription fee over the next several weeks.

Should Denver start Peyton Manning against the Patriots?
I think this is a serious question in theory, and ought to be one in practice, but I would be shocked if Gary Kubiak will give it any consideration. ...

SpaceX Fails To Land Rocket On A Ship Yet Again
SpaceX has already tried to land its Falcon 9 reusable rocket on a floating ship in the ocean multiple times and, unfortunately, it has not been ...

A Clever Flowchart That Accurately Follows the Lyrical Pattern of David Bowie’s ‘Modern Love’
In October 2011, David Bowie fan pinstripehourglass very cleverly arranged the lyrics of “ Modern Love ” into a flowchart that accurately followed ...

Resources last updated: 1/18/2016 10:15:21 PM