|
本帖最后由 roych 于 2012-7-8 04:58 编辑
1、改用单引号:- Set rsR = New ADODB.Recordset
- sql = "SELECT (count(r.PointID)*"
- sql = sql & Trim(主窗口.TB01.Text) & "-" & 主窗口.TB01.Text & ")"
- sql = sql & "/1000 AS 公里数" & " ,count(r.PointID) as 点数 "
- sql = sql & "FROM Result AS r WHERE r.type in ('G','S') and r.OBS_Time<>' ' GROUP BY datepart('ww',#" & r.OBS_Time & "#)"
复制代码 2、改成转义字符(个人不太赞成这种玩法,很容易出错)- Set rsR = New ADODB.Recordset
- sql = "SELECT (count(r.PointID)*"
- sql = sql & Trim(主窗口.TB01.Text) & "-" & 主窗口.TB01.Text & ")"
- sql = sql & "/1000 AS 公里数" & " ,count(r.PointID) as 点数 "
- sql = sql & "FROM Result AS r WHERE r.type in ('G','S') and r.OBS_Time<>' ' GROUP BY datepart(""WW"",#" & r.OBS_Time & "#)"
复制代码 如果上述字符串测试出错(可能出现拼写或者落下半边字符串等情况),请参考下面的代码,适当地换过来:- '单引号
- Sub test()
- t = "2012-7-8"
- s = "datepart('WW',#" & t & "#)"
- Debug.Print s
- End Sub
- '转移字符
- Sub test()
- t = "2012-7-8"
- s = "datepart(""WW"",#" & t & "#)"
- Debug.Print s
- End Sub
复制代码 |
|