Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

don't know fieldname

Status
Not open for further replies.

aarontra

Programmer
Oct 2, 2002
50
US
In ColdFusion is there a way to specify a field in a query when you do not know what the name of the field is?
What to be able to select any table in a database with one page.
I have done it with ASP, but ColdFusion?

Thank you
Aaron
 
You talk about specifying a field that you don't know the name of, but then you say what you're trying to do is select any table... so it's a little unclear about what it is you're trying to do.

The exact syntax for getting a list of tables in a database differs from type of database to type of database... for example for Oracle you would use:

Code:
<cfquery name=&quot;ALLDATABASES&quot; datasource=&quot;MYSOURCE&quot;>
SELECT * FROM ALL_TABLES
</cfquery>

for MS SQL Server, you would use:

Code:
<cfquery name=&quot;GetDatabases&quot; datasource=&quot;MYSOURCE&quot;>
SELECT name FROM sysobjects WHERE type = 'U'
</cfquery>


Then you could get a list of columns/fields in that table by executing a short query on the desired table, and reading the columnlist property:

Code:
<CFQUERY name=&quot;GetColumns&quot; datasource=&quot;MYSOURCE&quot;>
SELECT * FROM #whichtable#
</CFQUERY>
<CFSET mycolumnlist = #GetColumns.ColumnList#>

Hope it helps,
-Carl





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top