SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 information_schema get table field values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

purell
Starting Member

17 Posts

Posted - 01/13/2007 :  16:13:51  Show Profile  Reply with Quote
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

USA
145 Posts

Posted - 01/13/2007 :  19:43:25  Show Profile  Reply with Quote
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 - 01/15/2007 :  14:15:25  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000