RE: HELP! Need to Reference Field Names as Variables
Posted in 1996
Steven,
____________________________________________________________________________
rem radioterapia, which I immeritately manage, seldom agrees with what I say
marco greco (Catania, Italy) Work:
marcog@ctonline.it rem radioterapia 39 95 447828 fax 446558
(was mar.greco@agora.stm.it) Achea 39 95 503117
Steven,
rather than passing a record to your function, try to pass an array with
name and value of the columns on which you wish to operate (No need to access
systables & syscolumns, obviously).
From there on, it should be very easy to prepare each statement.
The downside is that you have to populate the array with brute force...
HTH,
MArco
--- On 14 Nov 1996 18:46:19 GMT Steven Frank <stevef@relation.com> wrote:
Here is what I'm trying to do. I need to perform a few simple actions on each
of the fields in a given table.
Unfortunately, the table has a very large number of fields and typing a 4
line
code segment for each field is a major pain.
I have included a sample function below that reads the list of field names
from
the SYSTABLES and SYSCOLUMNS tables and then loops through each. The looping
structure works fine (i.e. I can retrieve the field names and loop through
each
of them).
The problem is that I don't know how to reference the field name that I have
read into my variable. The usual notation for referencing a field is
TABLE.FIELD where FIELD is a constant. I need FIELD to be a variable.
Replies via email would be greatly appreciated (stevef@relation.com)
Here is the commented function;
# This function checks each field for a NULL value and replaces it w/a space
# The parameter is a RECORD type variable
Function CheckForNull(lMT_Department)
# Declare variable for parameter
# The variable lColName will hold the field name read from the query
Define lMT_Department Record Like MT_Department.*,
lColName Char(50)
# Declare a cusor to run through the specified table and return each
# column name - This has been tested in ISQL and works fine
Declare NullSelect Cursor For
Select colname From systables, syscolumns
Where systables.tabname = "mt_department"
And systables.tabid = syscolumns.tabid
# Here we go...getting each column name out of the specified table
ForEach NullSelect Into lColName
# Here is the problem
# I (obviously) get a compile time error
# 'lColName is not a member of table blah blah'
# but this is what I want to do
If lMT_Department.lColName Is Null Then
Let lMT_Department.lColName = " "
End If
End ForEach
Return lMT_Department.*
End Function
-----------------End of Original Message-----------------