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!

Is't possible to use column number instead of field name

Status
Not open for further replies.

poupou

Programmer
Jun 12, 2002
6
CA
I would like to use SQL code like

rename column xx to yy

But I would like to use position number instead xx because I don't know the name of my column but I know is place.

Thanks

Redg
 
select yy as xx from table

the as statement allows renaming fields or aggregates or concatenate char data types

Attitude is Everything
 
You could use the AFIELDS() function to get the current field name and then the always flexible macro expansion!

USE mytable
=AFIELDS(laFields)
lcSecond = laFields[2, 1]
ALTER TABLE mytable ;
RENAME COLUMN &lcSecond TO yy

Rick
 
If you use the "copy struct to TableStruct Extended" you will have a table where the record number "reccount()" is the column number.

Perhaps you could use that for the basis of some sort of macro/procedure that would use the structure to look-up the actual field name when you refer to a column number.

If your field names are "Excel" like e.g. "A", "B" etc., you can use the column number as a variable when referring to the column as an ASCII map character. Thus:
X=1 and chr(64+x)="A"
X=2 and chr(64+x)="B"
X=3 and chr(64+x)="C"

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top