ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

excel ³s±µ SQL 2008»yªk ¦p¦ó§ï¶i »P°j°é

excel ³s±µ SQL 2008»yªk ¦p¦ó§ï¶i »P°j°é

¤p§Ì§Q¥ÎEXCELŪ¨úSQL2008ªº¸ê®Æ¡A·Q­n±q¸ê®Æ®w¤¤§ì¥X¨Ó­pºâ¡A³Ì«á·Q¦A«ö·ÓªÑ²¼¥N½X¶]°j°é¡A¤U­±¬O¤p§Ì¿ý»sªº¥N½X¡A§Úı±o¦n¹³¥i¥H§ó²³æ¤@¨Ç¡A½Ð°ª¤â«üÂI¤@¤U¡A·íµM¿ý»sªº¥N½X¬O2330¡A³Ì«á2330·|¥Î¦¨ÅܼƨӶ]¡A¤£ª¾¹D¦³¤H¥i¥HÅý¤U­±ªº³s±µ¤è¦¡§ó¦n©Î§ó§Ö¤@¨Ç¡IÁÂÁÂ


¤p§Ì¥u·|³o¼Ë¼g¡A·íµM¦³°ª¤â¥i¥HÀ°¤p§Ì§ïªº§óº}«G¤@¨Ç
  1. Sub ªÑ²¼¸ê®Æ1()
  2. '

  3. '

  4.     Sheets("Sheet1").Select
  5.     Range("A1").Select
  6.     With ActiveSheet.QueryTables.Add(Connection:= _
  7.         "ODBC;DRIVER=SQL Server;SERVER=.;UID=sa;PWD=WXYZ1234;APP=Microsoft Office 2003;WSID=CS5111;DATABASE=stock" _
  8.         , Destination:=Range("A1"))
  9.         .CommandText = Array( _
  10.         "select * from (SELECT TOP 12 *  FROM stock.dbo.StockStore WHERE stockid=2330 ORDER BY sdate DESC) AAA ORDER BY sdate")
  11.         .Name = "¨Ó¦Û "
  12.         .FieldNames = True
  13.         .RowNumbers = False
  14.         .FillAdjacentFormulas = False
  15.         .PreserveFormatting = True
  16.         .RefreshOnFileOpen = False
  17.         .BackgroundQuery = True
  18.         .RefreshStyle = xlInsertDeleteCells
  19.         .SavePassword = True
  20.         .SaveData = True
  21.         .AdjustColumnWidth = True
  22.         .RefreshPeriod = 0
  23.         .PreserveColumnInfo = True
  24.         .Refresh BackgroundQuery:=False
  25.     End With

  26. End Sub
  27. Sub ªÑ²¼¸ê®Æ2()
  28. '

  29. '

  30. '
  31.     Sheets("Sheet2").Select
  32.     Range("A1").Select
  33.     With ActiveSheet.QueryTables.Add(Connection:= _
  34.         "ODBC;DRIVER=SQL Server;SERVER=.;UID=sa;PWD=WXYZ1234;APP=Microsoft Office 2003;WSID=CS5111;DATABASE=stock" _
  35.         , Destination:=Range("A1"))
  36.         .CommandText = Array( _
  37.         " select * from (SELECT TOP 12 sdate,stockid, CreditMoney,CreditTick FROM stock.dbo.CreditExchangeMonth WHERE stockid=2330 ORDER BY sdate DESC) AAA ORDER BY sdate" _
  38.         )
  39.         .Name = "¨Ó¦Û "
  40.         .FieldNames = True
  41.         .RowNumbers = False
  42.         .FillAdjacentFormulas = False
  43.         .PreserveFormatting = True
  44.         .RefreshOnFileOpen = False
  45.         .BackgroundQuery = True
  46.         .RefreshStyle = xlInsertDeleteCells
  47.         .SavePassword = True
  48.         .SaveData = True
  49.         .AdjustColumnWidth = True
  50.         .RefreshPeriod = 0
  51.         .PreserveColumnInfo = True
  52.         .Refresh BackgroundQuery:=False
  53.     End With
  54. End Sub
½Æ»s¥N½X

¦^´_ 2# joey0415
¬d¸ß¤w¸g¦s¦b¤£¦A¨Ï¥ÎAdd
°²³]¥N¸¹¬O2030~2032
´N¦P¤@­Ó¬d¸ß¨Ï¤§ÅܤÆ
  1. Sub ªÑ²¼¸ê®Æ1()
  2. For Each MyID In Array("2030","2031",2032")
  3.     With Sheets("Sheet1").QueryTables(1)
  4.         .CommandText = Array( _
  5.         "select * from (SELECT TOP 12 *  FROM stock.dbo.StockStore WHERE stockid=" & MyID & " ORDER BY sdate DESC) AAA ORDER BY sdate")
  6.         .Name = "¨Ó¦Û "
  7.         .FieldNames = True
  8.         .RowNumbers = False
  9.         .FillAdjacentFormulas = False
  10.         .PreserveFormatting = True
  11.         .RefreshOnFileOpen = False
  12.         .BackgroundQuery = True
  13.         .RefreshStyle = xlInsertDeleteCells
  14.         .SavePassword = True
  15.         .SaveData = True
  16.         .AdjustColumnWidth = True
  17.         .RefreshPeriod = 0
  18.         .PreserveColumnInfo = True
  19.         .Refresh BackgroundQuery:=False
  20.     End With
  21. Next
  22. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¥»©«³Ì«á¥Ñ joey0415 ©ó 2010-6-4 21:44 ½s¿è

[quote]¦^´_  joey0415
¬d¸ß¤w¸g¦s¦b¤£¦A¨Ï¥ÎAdd
°²³]¥N¸¹¬O2030~2032
´N¦P¤@­Ó¬d¸ß¨Ï¤§ÅܤÆ
  1. # Sub ªÑ²¼¸ê®Æ1()
  2. # For Each MyID In Array("2030","2031",2032")
  3. #     With Sheets("Sheet1").QueryTables(1)
  4. #         .CommandText = Array( _
  5. #         "select * from (SELECT TOP 12 *  FROM stock.dbo.StockStore WHERE stockid=" & MyID & " ORDER BY sdate DESC) AAA ORDER BY sdate")
  6. #         .Name = "¨Ó¦Û "
  7. #         .FieldNames = True
  8. #         .RowNumbers = False
  9. #         .FillAdjacentFormulas = False
  10. #         .PreserveFormatting = True
  11. #         .RefreshOnFileOpen = False
  12. #         .BackgroundQuery = True
  13. #         .RefreshStyle = xlInsertDeleteCells
  14. #         .SavePassword = True
  15. #         .SaveData = True
  16. #         .AdjustColumnWidth = True
  17. #         .RefreshPeriod = 0
  18. #         .PreserveColumnInfo = True
  19. #         .Refresh BackgroundQuery:=False
  20. #     End With
  21. # Next
½Æ»s¥N½X
½Ð°Ýª©¥D¡A¬O¤£¬O­n¥ý°õ¦æ¿é¤J±b¸¹»P±K½XªºSQL³s½u³]©w¡A¤~¯à¨Ï¥Îª©¥Dªº§å¦¸³]©w¡A½Ð°Ý­n¦p¦ó¼W¥[¦bª©¥D©Ò¼gªºµ{¦¡¤W©O¡H·PÁª©¥D¥Î¤ß¦^À³

TOP

§A¬JµM¤w¸g¿ý»s¥X¨Ó
¥i¨£§A±o¬d¸ß¤w¸g«Ø¥ß
©Ò¥H±b¸¹±K½XÀ³¸Ó³£³Q°O¿ý
§A¥ý®M¥Î¬Ý¬Ý¬O§_¦³¹F¨ìÅܤÆ
¦A°w¹ï¹J¨ìªº°ÝÃDµo°Ý
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¯¸¦b¥b¸ô¡A¤ñ¨«¨ì¥Ø¼Ð§ó¨¯­W¡C
ªð¦^¦Cªí ¤W¤@¥DÃD