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.
Author |
Topic |
purell
Starting Member
17 Posts |
Posted - 2007-01-13 : 16:13:51
|
I would know what the table name is going to be but want to select the values from the table dynamically. Since the table name will be dynamic.So instead of saying: select job_amt, job_email from table a.I need to say select * from table whatever (the name will be dynamic) where field_name like '%amt%' and field_name like '%email%'.So it give me those amt and email values without using the actual field names.Let's say i have 2 tables<u>table a</u>job_idjob_amtjob_email<u>table b</u>dance_idamt_dancedance_email |
|
MohammedU
Posting Yak Master
145 Posts |
Posted - 2007-01-13 : 19:43:25
|
Here is the sample...declare @tname sysname, @cname sysname, @sql nVarchar(1000) select @tname = 'sysobjects', @cname = 'sysindexes'select @sql = 'select * from '+@tname+' where name like ''%'+@cname+'%'' ' select @sqlexec sp_executesql @sqlMohammedU |
|
|
purell
Starting Member
17 Posts |
Posted - 2007-01-15 : 14:15:25
|
Isn't there a way to join ex: tablea and the table containing tablea's field names, then sayselect * from tablea where name(coming from the systable?) like '%amt%' and name like '%email%'?What do I join the systable and tablea on ? |
|
|
|
|
|