设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1378|回复: 1
打印 上一主题 下一主题

[模块/函数] SQL查询里如何实现表达式字符自动替换?

[复制链接]
跳转到指定楼层
1#
发表于 2010-3-31 13:12:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我的数据库里有很多如下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

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2010-4-11 10:38:45 | 只看该作者
没有人能帮忙解决吗?或者是我的思路有问题?再次拜谢!急!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-18 01:33 , Processed in 0.075255 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表