Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Как подставить в Select переменные / 2 сообщений из 2, страница 1 из 1
20.11.2001, 15:23
    #32017361
alenab
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Как подставить в Select переменные
Hi!
Do you know how to use SQL to make an 'indirection'. You remember in the C language, how you can treat the contents of a variable as a pointer to another variable location, or in other 4th generation languages (& some OS stuff), you can use a 'handle' to hold an indirect reference to another variable...

I want to do something similar in SQL. I want a column in a table to hold a string that is a column name. I want to create an SQL statement that will use the value of that column name and perform a comparison.

For example, there it a table:
Table: T_Compare_Columns
( col_name char(50) )

Another table:
Table: T_Datastuff
( name_ch char(20),
county_ch char(20),
salary_dc decimal ( 12,2) )

Insert a line into T_Compare_columns:
Insert into T_Compare_columns
values ( 'county_cd' )

Then use that to perform an 'indirect reference' comparison. This statement is pure fiction. I know it will not work in this form:

select *
from T_Datastuff
where T_Compare_column.col_name = T_datastuff.COLUMN_NAME
and t_datastuff.COLUMN_NAME = 'RICHLAND'

Thank you,

Alena
...
Рейтинг: 0 / 0
21.11.2001, 07:23
    #32017405
Как подставить в Select переменные
There are 3 things in MSSQL to help to solve the task:
1) Operator "EXEC(string_expression)" for executing a dynamic query.
2,3) System tables "syscolumns" and "sysobjects", where there are columns' and tables' names.
It is enough.
...
Рейтинг: 0 / 0
Форумы / Microsoft SQL Server [игнор отключен] [закрыт для гостей] / Как подставить в Select переменные / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]