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
 SQL Server Development (2000)
 information_schema get table field values

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_id
job_amt
job_email

<u>table b</u>
dance_id
amt_dance
dance_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 @sql
exec sp_executesql @sql


MohammedU
Go to Top of Page

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 say

select * from tablea where name(coming from the systable?) like '%amt%' and name like '%email%'?

What do I join the systable and tablea on ?
Go to Top of Page
   

- Advertisement -