暱稱: joey0415
中學生
- 帖子
- 361
- 主題
- 57
- 精華
- 0
- 積分
- 426
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- 2003,2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2010-5-13
- 最後登錄
- 2022-12-8
|
執行階段錯誤13,型態不符合與sql語法指點
小弟最近在寫sql語法,最後要代入excel vba中, 前面的一段code可以用,不過改成另一最sql的語句卻發生錯誤,不過這一段語句在sql server中是可以執行的,在vba執行中出現的是「執行階段錯誤13,型態不符合」,請高手指點一下,另一個問題是當語句很長時怎麼換行呢?- Sub 股票合併測試()
- '
- Sheets("Sheet4").Select
- Range("A1").Select
- With ActiveSheet.QueryTables.Add(Connection:= _
- "ODBC;DRIVER=SQL Server;SERVER=.;UID=sa;PWD=wxyz1234;APP=Microsoft Office 2003;WSID=CS5111;DATABASE=stock" _
- , Destination:=Range("A1"))
- .CommandText = Array("select a.sdate,a.stockid,a.buy,a.sell,b.sdate,b.stockid,b.eq0,b.eq1 from dbo.CompTradeMonth a inner join dbo.StockStore b on a.stockid=b.stockid where a.sdate='2010-03-31 00:00:00.000' and b.sdate='2010-03-31 00:00:00.000' and a.stockid>1000")
- .Name = "來自 "
- .FieldNames = True
- .RowNumbers = False
- .FillAdjacentFormulas = False
- .PreserveFormatting = True
- .RefreshOnFileOpen = False
- .BackgroundQuery = True
- .RefreshStyle = xlInsertDeleteCells
- .SavePassword = True
- .SaveData = True
- .AdjustColumnWidth = True
- .RefreshPeriod = 0
- .PreserveColumnInfo = True
- .Refresh BackgroundQuery:=False
- End With
- End Sub
複製代碼- Sub 股票合併測試()
- '
- Sheets("Sheet4").Select
- Range("A1").Select
- With ActiveSheet.QueryTables.Add(Connection:= _
- "ODBC;DRIVER=SQL Server;SERVER=.;UID=sa;PWD=wxyz1234;APP=Microsoft Office 2003;WSID=CS5111;DATABASE=stock" _
- , Destination:=Range("A1"))
- .CommandText = Array("select a.sdate,a.stockid,a.eq0,a.eq1,a.eq5,a.eq10,a.eq15,a.eq20,a.eq30,a.eq50,a.eq100,a.eq200,a.eq400,a.eq600,a.eq800,a.eq1000,a.eq,b.sdate,b.stockid,b.Buy,b.Sell,b.UD,b.EQ from dbo.StockStore a inner join dbo.CompTradeMonth b on a.stockid=b.stockid where a.sdate='2010-03-31 00:00:00.000' and b.sdate='2010-03-31 00:00:00.000' and a.stockid>1100")
- .Name = "來自 "
- .FieldNames = True
- .RowNumbers = False
- .FillAdjacentFormulas = False
- .PreserveFormatting = True
- .RefreshOnFileOpen = False
- .BackgroundQuery = True
- .RefreshStyle = xlInsertDeleteCells
- .SavePassword = True
- .SaveData = True
- .AdjustColumnWidth = True
- .RefreshPeriod = 0
- .PreserveColumnInfo = True
- .Refresh BackgroundQuery:=False
- End With
- End Sub
複製代碼 |
|