0
我使用excel宏從AS400中提取一些數據。在AS400中,這個特定列(Ref)顯示20100729000078154,但是當我將它提取到excel時,它將是2.01007E + 16。我需要將20100729000078154作爲最終輸出。這是我用來提取AS400的信息的宏: -在Excel中轉換爲文本格式
Sub Extract()
Dim StrSQl As String
FromA = Format(Sheet1.Range("B3"))
FromB = Format(Sheet1.Range("B4"))
FromC = Format(Sheet1.Range("B5"))
FromD = Format(Sheet1.Range("B6"))
StrSQl = "select Cno,Itno,Ref from test "
StrSQl = StrSQl & " where Cno= " & FromA & " and Itno like " & FromB & " and "
StrSQl = StrSQl & " Ref >= " & FromC & " and Ref <= " & FromD & " "
StrSQl = StrSQl & " order by Cno "
con = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User Id=yyyyy;Password=zzzzz"
Set Db = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.recordset")
Db.ConnectionString = con
Db.Open
rs.Open StrSQl, Db, 3, 3
Sheet2.Cells(1, 1).CopyFromRecordset rs
rs.Close
Set rs = Nothing
Set cn = Nothing
End Sub
是'Ref'是整數還是字符串? – egrunin 2010-10-04 02:04:23
因爲20100729000078154在Excel中不是有效的日期格式,所以您可能想要在SQL語句中格式化它(例如yyyy-mm-dd hh:mm:ss)。 – 2010-10-04 02:10:03