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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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>

<u>table b</u>

Posting Yak Master

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

Go to Top of Page

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  
 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.02 seconds. Powered By: Snitz Forums 2000