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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shorten # Lines

Status
Not open for further replies.

MikeKohler

Technical User
Jun 22, 2001
115
CA
Hi, I have the following code:

db.Execute "ALTER TABLE PT001 " & "DROP COLUMN GPS_RESERVED;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN dROLLSTATUS;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN dSTATUSCODE;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN dKEY;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN dSERIES;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN DNAMEADDRESSTYPE;"
db.Execute "ALTER TABLE PT001 " & "DROP COLUMN dCLASSID;"

What I was wondering, is their a syntax where I cand do this in one line and only use the the command DROP COLUMN once?
Thank you, Michael Kohler
mkohler@telusplanet.net
 
Well, yes -sort of-, but then if this is all there is -why bother?

The Shortening could easily be achieveid in a sense, with a loop. Everything -except the actual fieldname- in the execute command is the same, so you could out the 'constant' part in one string and concatenate with the field name, as in:

MySql = ""ALTER TABLE PT001 DROP COLUMN "

in a loop

Idx = 0
Do While Idx <= UBound(FldLst)
[tab]db.Execute MySql & FldLst(Idx) & &quot;;&quot;
[tab]Idx = Idx + 1
Loop

Of course, the field names would be in the properly dimensioned string array &quot;FldLst&quot;

On the other hand, if you haven't read the MS Help on the alter / drop statement, and are asking if you can 'stack/list' the column names in a single statement, then you should read the help system, to find the answer















(is NO!)

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top