Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 21st, 2003, 05:15 AM
connectvikram connectvikram is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 1 connectvikram User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to connectvikram Send a message via AIM to connectvikram
Question use a variable instead of column name in SQL query

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

Reply With Quote
  #2  
Old April 21st, 2003, 12:03 PM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 1,784 swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level)swampBoogie User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 21 h 42 m 49 sec
Reputation Power: 37
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.

Reply With Quote
  #3  
Old October 10th, 2003, 02:26 AM
marco.morreale marco.morreale is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 marco.morreale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question column name in a variable

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > use a variable instead of column name in SQL query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT