Office中国论坛/Access中国论坛

标题: SQL查询里如何实现表达式字符自动替换? [打印本页]

作者: RickyZjw-3721    时间: 2010-3-31 13:12
标题: SQL查询里如何实现表达式字符自动替换?
我的数据库里有很多如下SQL代码的选择查询,因为数据表的字段从2009年变为2010年但相应的选择查询中的表达式却不能随之改变。
SELECT DISTINCTROW AccountsDescription.Acct, AccountsDescription.AcctDescription, Sum(PP_Expenses.P200901) AS P200901, Sum(PP_Expenses.P200902) AS P200902, Sum(PP_Expenses.P200903) AS P200903, Sum(PP_Expenses.P200904) AS P200904, Sum(PP_Expenses.P200905) AS P200905, Sum(PP_Expenses.P200906) AS P200906, Sum(PP_Expenses.P200907) AS P200907, Sum(PP_Expenses.P200908) AS P200908, Sum(PP_Expenses.P200909) AS P200909, Sum(PP_Expenses.P200910) AS P200910, Sum(PP_Expenses.P200911) AS P200911, Sum(PP_Expenses.P200912) AS P200912
FROM AccountsDescription RIGHT JOIN PP_Expenses ON AccountsDescription.Acct = PP_Expenses.Acct
WHERE (((PP_Expenses.ActivCtr)="10102"))
GROUP BY AccountsDescription.Acct, AccountsDescription.AcctDescription;


我想通过如下的一段代码来实现整体替换,但是提示出错。还请那位热心的高手出招帮忙指点一下。在此先行谢过了!
Function ReplaceQryWord()
Dim conn As New ADODB.Connection
'Dim OldWord As String
Dim C As Integer
Dim i As Integer
Set conn = CurrentProject.Connection
C = 1
For i = 0 To CurrentData.AllQueries.Count - 1
    If CurrentData.AllQueries(i).Type = "Select Query" Then
       DoCmd. Replace("P2009", "P2009", "P2010")
    End If
    C = C + 1
Next i
MsgBox "更改查询老字段名结束。"

End Function


作者: RickyZjw-3721    时间: 2010-4-11 10:38
没有人能帮忙解决吗?或者是我的思路有问题?再次拜谢!急!!




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3