程序代码:
*-- tcAls - 要修改结构的临时表别名
*-- tcDef - 要添加的字段定义: 字段名,类型,长度,小数位,允许空值(0 or 1)
Function FieldAdd(tcAls, tcDef)
Local nOldArea, cTemp, ii, jj, kk
Local cFldName, cFldType, cFldLen, cFldDec, lAllowNull
Local array aOld[1], aNew[1]
m.nOldArea = Select(0)
m.cFldName = GetWordNum(m.tcDef, 1, ',')
m.cFldType = GetWordNum(m.tcDef, 2, ',')
m.cFldLen = Cast(GetWordNum(m.tcDef, 3, ',') as I)
m.cFldDec = Cast(GetWordNum(m.tcDef, 4, ',') as I)
m.lAllowNull = Cast(Cast(GetWordNum(m.tcDef, 5, ',') as I) as L)
m.ii = AFields(m.aOld, m.tcAls)
If Ascan(m.aOld, m.cFldName, 1, -1, 1, 1+2+4) > 0
*-- 字段已经存在
Else
m.ii = m.ii + 1
m.jj = Alen(m.aOld, 2)
Dimension aOld[m.ii, m.jj]
m.aOld[m.ii, 1] = m.cFldName
m.aOld[m.ii, 2] = m.cFldType
m.aOld[m.ii, 3] = m.cFldLen
m.aOld[m.ii, 4] = m.cFldDec
m.aOld[m.ii, 5] = m.lAllowNull
Dimension aNew[m.ii,5]
For m.kk = 1 to Alen(m.aNew, 2)
For m.jj = 1 to m.ii
m.aNew[m.jj, m.kk] = m.aOld[m.jj, m.kk]
EndFor
EndFor
m.cTemp = Sys(2015)
Create Cursor (m.cTemp) from array aNew
Append From Dbf(m.tcAls)
Use Dbf(m.cTemp) Again In Select(m.tcAls) Alias (m.tcAls)
Use in Select(m.cTemp)
EndIf
Select (m.nOldArea)
EndFunc
把这个函数加到你的过程集里,或者单独放到一个prg里,并且 set proc to xxx.prg addi
最后把
alter table hbwj add &lmmoe c(254)
换成
FieldAdd('hbwj', lmmce+',C,254')