|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
Can i replace a variable name instead of a column name in SELECT, UPDATE queries ? I have three tables TABLE_A, TABLE_B and TABLE_C. The TABLE_C is having columns as table_name and column_name. The values for these columns would be : for table_name: TABLE_A and column_name would have the data as column names of table TABLE_A. Now I want to fetch records from TABLE_C which will return me a column name of TABLE_A and i want to compare the values of this column in tables TABLE_A and TABLE_B I have the query as: UPDATE EXTERNAL_CONTRACT_DIRTY SET id_sts_download = 'A' FROM TABLE_A ECD, TABLE_B EC WHERE CONVERT(VARCHAR(10), ECD.dt_download,101)= @dt_download AND ECD.id_sts_download = 'E' AND ECD.@nm_col <> ECD.@nm_col I am getting an error" invalid syntax near @nm_col". I have defined varibales @nm_col and @dt_download. I am using SYBASE as database. Please can anyone help me in this. Thanx in advance.. vikram |
|
#2
|
|||
|
|||
|
Redesign the data model. You shouldn't store meta data like that.
You can't treat columns and tables as being the same as variables in a programming language. |
|
#3
|
|||
|
|||
|
Hi,
I have the same problem. Did you find a solution? Here is my code SELECT @colValue = inserted.[@colName] FROM inserted The error is: @colName is not a valid column name Marco |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > use a variable instead of column name in SQL query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|