Don't know the field name but do know the column order

Don't know the field name but do know the column order

Post by John Shearin » Sun, 04 Mar 2001 05:12:10



Hi All,
I need to write a select statement that will select columns from a table
based on the column order.
For instance:
If I had a table called (MyTable) and it had 3 fields call MyField1,
MyField2 and MyField3
I would like to write a select statement the selects the data from MyField3
with a select statement like this:
SELECT 3 FROM MyTable.

I need to do this because I do not have the name of the field at run time
but I will know the position of the column in the table.

Thanks, John

 
 
 

Don't know the field name but do know the column order

Post by Rob Morron » Sun, 04 Mar 2001 06:18:08


The Names of the fields are included in the META data from the recordset.

One method that I have used is to execute the following:

recordSet.Open "SELECT * FROM MyTable WHERE 1=2", ConnectionString

1 will never equal 2, so what is returned is an empty recordset that still
contains all of the META data.

recordSet(3).name will be the name of the column.
--

Rob Morrone
http://www.webstrands.com


Quote:> Hi All,
> I need to write a select statement that will select columns from a table
> based on the column order.
> For instance:
> If I had a table called (MyTable) and it had 3 fields call MyField1,
> MyField2 and MyField3
> I would like to write a select statement the selects the data from
MyField3
> with a select statement like this:
> SELECT 3 FROM MyTable.

> I need to do this because I do not have the name of the field at run time
> but I will know the position of the column in the table.

> Thanks, John


 
 
 

Don't know the field name but do know the column order

Post by DaveSat » Sun, 04 Mar 2001 06:47:28


something that uses something like this ?:

SELECT TABLE_NAME + ".." + COLUMN_NAME
FROM information_schema.columns
WHERE TABLE_NAME = "dtproperties"
AND ORDINAL_POSITION = 5
--
HTH,
David Satz
Principal Software Engineer
Hyperion Solutions
->Using SQL Server 7.0 SP3/6.5 SP5a/Cold Fusion 4.5.1 SP2/VSS
(Please reply to group only - emails answered rarely)
-----------------------------------------------------------------


Quote:> Hi All,
> I need to write a select statement that will select columns from a table
> based on the column order.
> For instance:
> If I had a table called (MyTable) and it had 3 fields call MyField1,
> MyField2 and MyField3
> I would like to write a select statement the selects the data from
MyField3
> with a select statement like this:
> SELECT 3 FROM MyTable.

> I need to do this because I do not have the name of the field at run time
> but I will know the position of the column in the table.

> Thanks, John

 
 
 

Don't know the field name but do know the column order

Post by John Shearin » Wed, 07 Mar 2001 09:31:35


Hi Rob,
That is a good trick.
Unfortunatly I am trying to do all this work from inside the stored
procedure. This is because I am trying to keep all my business logic on the
back end.
Thanks, John

>The Names of the fields are included in the META data from the recordset.

>One method that I have used is to execute the following:

>recordSet.Open "SELECT * FROM MyTable WHERE 1=2", ConnectionString

>1 will never equal 2, so what is returned is an empty recordset that still
>contains all of the META data.

>recordSet(3).name will be the name of the column.
>--

>Rob Morrone
>http://www.webstrands.com

 
 
 

Don't know the field name but do know the column order

Post by John Shearin » Wed, 07 Mar 2001 09:39:48


Hi Dave,

Yes this is what I am looking for.
Thanks for your help,
John


>something that uses something like this ?:

>SELECT TABLE_NAME + ".." + COLUMN_NAME
>FROM information_schema.columns
>WHERE TABLE_NAME = "dtproperties"
>AND ORDINAL_POSITION = 5
>--
>HTH,
>David Satz
>Principal Software Engineer
>Hyperion Solutions
>->Using SQL Server 7.0 SP3/6.5 SP5a/Cold Fusion 4.5.1 SP2/VSS
>(Please reply to group only - emails answered rarely)
>-----------------------------------------------------------------

 
 
 

1. SQL server name has been changed and don't know why

Hello,

Original SQL server 7 name: server_1
Computer name: server_1

With above seeting the computer and SQL server 7 was
working just fine for several years and all of sudden
everything start to fail, ex. DB connection error, so I

answer like "server_12".  It seems like the SQL server is
thinking that it is "server_12" instead of "server_1" and
I have no idea why.  And the computer name has not been
changed at all and when I go into the SQL Enterprise
Manager I still see the "server_1" instance.

How can I change the server name back to "server_1"?
Can I just use the "sp_dropserver" and "sp_addserver" to
acomplish this?
Do I need to edit the registry in any way?

TIA,

David Kim

2. isql return codes

3. I don't know the full name of the director

4. Error log

5. I don′t know oracle, but i need know

6. Request: example of an ODBC connection to btrieve data from Excel VBA

7. I've just replaced the last dBA and don't know the sa password

8. image extender CURRENT SERVER problem

9. Oninit didn't work fine and I don't know why

10. Funny Behaving Locate - don't know where's the problem

11. Don't know if it's possible : grouping

12. ODBC data source, need to know the column names and column types