Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to use variable within the query

Author  Topic 

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-06-22 : 02:39:30
Is it possible to declare a variable in a query and after assigning value to it, we may be able to use it as a column for another table within the same query like


select @column_name from
(select @column_name = tpm.column_name
from test_param_map tpm join wafer on tpm.lot_sequence = wafer.lot_sequence join P9240502_001 d on
wafer.wafer_sequence = d.wafer_sequence
where tpm.test_name = 'FCOM short') a join
(select tpm.test_name, tpm.column_name, d.+@column_name
from test_param_map tpm join wafer on tpm.lot_sequence = wafer.lot_sequence join P9240502_001 d on
wafer.wafer_sequence = d.wafer_sequence
where tpm.test_name = 'FCOM short') b on
a.+@column_name = b.column_name

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-06-22 : 05:52:30
i don't believe it is possible this way. but with the use of EXEC you could make it work

exec 'select ' + @column_name + 'from ...'

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -