N
N
Nevars2015-09-18 12:53:02
SQL
Nevars, 2015-09-18 12:53:02

How to query a table whose link is stored in another table?

Good afternoon.
There is a table consisting of three columns: id, dictionary name, link_to_dictionary.
The "link_to_dictionary" column stores the full name of the table it refers to.
Question: how can I make a query to a table using an existing link?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artur Polozov, 2015-09-24
@Nevars

use dynamics:

DECLARE @tableName NVARCHAR(20); 
SELECT @tableName = dictionary_link FROM table1;

EXEC(' SELECT * FROM '[email protected]+' WHERE 1 = 1 ');

Next, you can take out the data in the temporary:
CREATE TABLE #test (id INT);
INSERT INTO #test EXEC(' SELECT id FROM '[email protected]+' WHERE 1 = 1 ');
-- или так:
EXEC(' SELECT id INTO #test FROM '[email protected]+' WHERE 1 = 1 ');

A
Andrey Lastochkin, 2015-09-18
@lasalas

the one who designed this - castrate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question