sql3 = "IF EXISTS (SELECT name FROM sysobjects WHERE name='sehaoxilie') DROP TABLE sehaoxilie select shdj.kehu,shdj.ys,shdj.sehao,shdj.dj,cint(sehao)-[min_sehao]+1 as xl,shdj.pz,shdj.djrq,shdj.dyf INTO sehaoxilie FROM shdj INNER JOIN 记录数查询 ON shdj.kehu=记录数查询.kehu WHERE ((shdj.dyf)<>1)"
With objCm
.ActiveConnection = objCn
.CommandText = sql3
.CommandType = adCmdText
.Execute
End With
Set objCm.ActiveConnection = Nothing
objCn.Close
具体代码如上,提示错误是红色部份cint(sehao) 错误显示CInt 是不可识别函数,我用CAST(sehao as int)转换时碰sehao 字段数据中有汉字或字母数据时就出错(如sehao="S001"或者sehao="黑色001")。
我终于搞定了,我用的是case.......when........end 函数 和字符取值函数ACSSII() substring()
具体是这样的:
sql3 = "IF EXISTS (SELECT name FROM sysobjects WHERE name='sehaoxilie') DROP TABLE sehaoxilie select shdj.kehu,shdj.ys,shdj.sehao,shdj.dj,cast(case when acssii(sehao)>=48 and acssii(sehao)<=57 then sehao else substring(sehao,2,20) end as int)-[min_sehao]+1 as xl,shdj.pz,shdj.djrq,shdj.dyf INTO sehaoxilie FROM shdj INNER JOIN 记录数查询 ON shdj.kehu=记录数查询.kehu WHERE ((shdj.dyf)<>1)"
总记录:4篇 页次:1/1 9 1 :