{"id":92,"date":"2008-03-02T11:20:49","date_gmt":"2008-03-02T11:20:49","guid":{"rendered":""},"modified":"2008-03-02T11:20:49","modified_gmt":"2008-03-02T11:20:49","slug":"92","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=92","title":{"rendered":"SQL SERVER \u4e0eACCESS\u3001EXCEL\u7684\u6570\u636e\u8f6c\u6362"},"content":{"rendered":"<p>\u719f\u6089SQL SERVER 2000\u7684\u6570\u636e\u5e93\u7ba1\u7406\u5458\u90fd\u77e5\u9053\uff0c\u5176DTS\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u7684\u5bfc\u5165\u5bfc\u51fa\uff0c\u5176\u5b9e\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528Transact-SQL\u8bed\u53e5\u8fdb\u884c\u5bfc\u5165\u5bfc\u51fa\u64cd\u4f5c\u3002\u5728Transact-SQL\u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u4e3b\u8981\u4f7f\u7528OpenDataSource\u51fd\u6570\u3001OPENROWSET \u51fd\u6570\uff0c\u5173\u4e8e\u51fd\u6570\u7684\u8be6\u7ec6\u8bf4\u660e\uff0c\u8bf7\u53c2\u8003SQL\u8054\u673a\u5e2e\u52a9\u3002\u5229\u7528\u4e0b\u8ff0\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5341\u5206\u5bb9\u6613\u5730\u5b9e\u73b0SQL SERVER\u3001ACCESS\u3001EXCEL\u6570\u636e\u8f6c\u6362\uff0c\u8be6\u7ec6\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<p>\u4e00\u3001SQL SERVER \u548cACCESS\u7684\u6570\u636e\u5bfc\u5165\u5bfc\u51fa<\/p>\n<p>\u5e38\u89c4\u7684\u6570\u636e\u5bfc\u5165\u5bfc\u51fa\uff1a<br \/>\u4f7f\u7528DTS\u5411\u5bfc\u8fc1\u79fb\u4f60\u7684Access\u6570\u636e\u5230SQL Server\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u6b65\u9aa4: <br \/>\u3000\u30001)\u5728SQL SERVER\u4f01\u4e1a\u7ba1\u7406\u5668\u4e2d\u7684Tools\uff08\u5de5\u5177\uff09\u83dc\u5355\u4e0a\uff0c\u9009\u62e9Data Transformation <br \/>\u3000\u30002)Services\uff08\u6570\u636e\u8f6c\u6362\u670d\u52a1\uff09\uff0c\u7136\u540e\u9009\u62e9&nbsp;&nbsp;czdImport Data\uff08\u5bfc\u5165\u6570\u636e\uff09\u3002 <br \/>\u3000\u30003)\u5728Choose a Data Source\uff08\u9009\u62e9\u6570\u636e\u6e90\uff09\u5bf9\u8bdd\u6846\u4e2d\u9009\u62e9Microsoft Access as the Source\uff0c\u7136\u540e\u952e\u5165\u4f60\u7684.mdb\u6570\u636e\u5e93(.mdb\u6587\u4ef6\u6269\u5c55\u540d)\u7684\u6587\u4ef6\u540d\u6216\u901a\u8fc7\u6d4f\u89c8\u5bfb\u627e\u8be5\u6587\u4ef6\u3002 <br \/>\u3000\u30004)\u5728Choose a Destination\uff08\u9009\u62e9\u76ee\u6807\uff09\u5bf9\u8bdd\u6846\u4e2d\uff0c\u9009\u62e9Microsoft OLE\u3000DB Prov ider for SQL\u3000Server\uff0c\u9009\u62e9\u6570\u636e\u5e93\u670d\u52a1\u5668\uff0c\u7136\u540e\u5355\u51fb\u5fc5\u8981\u7684\u9a8c\u8bc1\u65b9\u5f0f\u3002 <br \/>\u3000\u30005)\u5728Specify Table Copy\uff08\u6307\u5b9a\u8868\u683c\u590d\u5236\uff09\u6216Query\uff08\u67e5\u8be2\uff09\u5bf9\u8bdd\u6846\u4e2d\uff0c\u5355\u51fbCopy tables\uff08\u590d\u5236\u8868\u683c\uff09\u3002 <br \/>&nbsp;&nbsp;&nbsp;&nbsp;6)\u5728Select Source Tables\uff08\u9009\u62e9\u6e90\u8868\u683c\uff09\u5bf9\u8bdd\u6846\u4e2d\uff0c\u5355\u51fbSelect All\uff08\u5168\u90e8\u9009\u5b9a\uff09\u3002\u4e0b\u4e00\u6b65\uff0c\u5b8c\u6210\u3002<\/p>\n<p>Transact-SQL\u8bed\u53e5\u8fdb\u884c\u5bfc\u5165\u5bfc\u51fa\uff1a<br \/>1.\u5728SQL SERVER\u91cc\u67e5\u8be2access\u6570\u636e:<\/p>\n<p>Select * FROM OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:DB.mdb&#8221;;User ID=Admin;Password=&#8217;)&#8230;\u8868\u540d<\/p>\n<p>2.\u5c06access\u5bfc\u5165SQL server<br \/>\u5728SQL SERVER \u91cc\u8fd0\u884c:<br \/>Select * INTO newtable FROM OPENDATASOURCE (&#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:DB.mdb&#8221;;User ID=Admin;Password=&#8217; )&#8230;\u8868\u540d<\/p>\n<p>3.\u5c06SQL SERVER\u8868\u91cc\u7684\u6570\u636e\u63d2\u5165\u5230Access\u8868\u4e2d<br \/>\u5728SQL SERVER \u91cc\u8fd0\u884c\uff1a<br \/>insert into OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221; c:DB.mdb&#8221;;User ID=Admin;Password=&#8217;)&#8230;\u8868\u540d (\u5217\u540d1,\u5217\u540d2) select \u5217\u540d1,\u5217\u540d2&nbsp;&nbsp;from&nbsp;&nbsp;sql\u8868<\/p>\n<p>\u5b9e\u4f8b\uff1a<br \/>insert into&nbsp;&nbsp;OPENROWSET(&#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;C:db.mdb&#8217;;&#8217;admin&#8217;;&#8221;, Test) select id,name from Test<\/p>\n<p>Insert INTO OPENROWSET(&#8216;Microsoft.Jet.OLEDB.4.0&#8217;, &#8216;c:\trade.mdb&#8217;; &#8216;admin&#8217;; &#8221;, \u8868\u540d) Select * FROM sqltablename<\/p>\n<p>\u4e8c\u3001SQL SERVER \u548cEXCEL\u7684\u6570\u636e\u5bfc\u5165\u5bfc\u51fa<\/p>\n<p>1\u3001\u5728SQL SERVER\u91cc\u67e5\u8be2Excel\u6570\u636e:<\/p>\n<p>Select * FROM OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:\book1.xls&#8221;;User ID=Admin;Password=;Extended properties=Excel 5.0&#8217;)&#8230;[Sheet1$]<\/p>\n<p>\u4e0b\u9762\u662f\u4e2a\u67e5\u8be2\u7684\u793a\u4f8b\uff0c\u5b83\u901a\u8fc7\u7528\u4e8e Jet \u7684 OLE DB \u63d0\u4f9b\u7a0b\u5e8f\u67e5\u8be2 Excel \u7535\u5b50\u8868\u683c\u3002<br \/>Select * FROM OpenDataSource ( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:Financeaccount.xls&#8221;;User ID=Admin;Password=;Extended properties=Excel 5.0&#8217;)&#8230;xactions<\/p>\n<p>2\u3001\u5c06Excel\u7684\u6570\u636e\u5bfc\u5165SQL server :<br \/>Select * into newtable FROM OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:\book1.xls&#8221;;User ID=Admin;Password=;Extended properties=Excel 5.0&#8217;)&#8230;[Sheet1$]<\/p>\n<p>\u5b9e\u4f8b:<br \/>Select * into newtable FROM OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:Financeaccount.xls&#8221;;User ID=Admin;Password=;Extended properties=Excel 5.0&#8217;)&#8230;xactions<\/p>\n<p>3\u3001\u5c06SQL SERVER\u4e2d\u67e5\u8be2\u5230\u7684\u6570\u636e\u5bfc\u6210\u4e00\u4e2aExcel\u6587\u4ef6<br \/>T-SQL\u4ee3\u7801\uff1a<br \/>EXEC master..xp_cmdshell &#8216;bcp \u5e93\u540d.dbo.\u8868\u540dout c:Temp.xls -c -q -S&#8221;servername&#8221; -U&#8221;sa&#8221; -P&#8221;&#8221;&#8216;<br \/>\u53c2\u6570\uff1aS \u662fSQL\u670d\u52a1\u5668\u540d\uff1bU\u662f\u7528\u6237\uff1bP\u662f\u5bc6\u7801<br \/>\u8bf4\u660e\uff1a\u8fd8\u53ef\u4ee5\u5bfc\u51fa\u6587\u672c\u6587\u4ef6\u7b49\u591a\u79cd\u683c\u5f0f<\/p>\n<p>\u5b9e\u4f8b:EXEC master..xp_cmdshell &#8216;bcp saletesttmp.dbo.CusAccount out c:\temp1.xls -c -q -S&#8221;pmserver&#8221; -U&#8221;sa&#8221; -P&#8221;sa&#8221;&#8216;<\/p>\n<p>EXEC master..xp_cmdshell &#8216;bcp &#8220;Select au_fname, au_lname FROM pubs..authors orDER BY au_lname&#8221; queryout C: authors.xls -c -Sservername -Usa -Ppassword&#8217;<\/p>\n<p>4\u3001\u5728SQL SERVER\u91cc\u5f80Excel\u63d2\u5165\u6570\u636e:<\/p>\n<p>insert into OpenDataSource( &#8216;Microsoft.Jet.OLEDB.4.0&#8242;,&#8217;Data Source=&#8221;c:Temp.xls&#8221;;User ID=Admin;Password=;Extended properties=Excel 5.0&#8217;)&#8230;table1 (A1,A2,A3) values (1,2,3)<\/p>\n<p>T-SQL\u4ee3\u7801\uff1a<br \/>Insert INTO&nbsp;&nbsp;<br \/> OPENDATASOURCE(&#8216;Microsoft.JET.OLEDB.4.0&#8242;,&#8217;Extended Properties=Excel 8.0;Data source=C:\traininginventur.xls&#8217;)&#8230;[Filiale1$]&nbsp;&nbsp;(bestand, produkt) VALUES (20, &#8216;Test&#8217;)&nbsp;&nbsp;<\/p>\n<p>\u603b\u7ed3\uff1a\u5229\u7528\u4ee5\u4e0a\u8bed\u53e5\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06SQL SERVER\u3001ACCESS\u548cEXCEL\u7535\u5b50\u8868\u683c\u8f6f\u4ef6\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u8f6c\u6362\uff0c\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u6781\u5927\u65b9\u4fbf\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u719f\u6089SQL SERVER 2000\u7684\u6570\u636e\u5e93\u7ba1\u7406\u5458\u90fd\u77e5\u9053\uff0c\u5176DTS\u53ef\u4ee5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-DB"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}