MSSQL Óë EXCEL»¥²Ù×÷
SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö
1¡¢ÔÚSQL SERVERÀï²éѯExcelÊý¾Ý:
-- ======================================================
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
ÏÂÃæÊǸö²éѯµÄʾÀý£¬Ëüͨ¹ýÓÃÓÚ Jet µÄ OLE DB Ìṩ³ÌÐò²éѯ Excel µç×Ó±í¸ñ¡£
SELECT *
from OpenDataSource ( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
-------------------------------------------------------------------------------------------------
2¡¢½«ExcelµÄÊý¾Ýµ¼ÈëSQL server :
-- ======================================================
SELECT * into newtable
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
ʵÀý:
SELECT * into newtable
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
-------------------------------------------------------------------------------------------------
3¡¢½«SQL SERVERÖвéѯµ½µÄÊý¾Ýµ¼³ÉÒ»¸öExcelÎļþ
-- ======================================================
T-SQL´úÂ룺
EXEC master..xp_cmdshell 'bcp ¿âÃû.dbo.±íÃûout c:\Temp.xls -c -q -S"servername" -U"sa" -P""'
²ÎÊý£ºS ÊÇSQL·þÎñÆ÷Ãû£»UÊÇÓû§£»PÊÇÃÜÂë
˵Ã÷£º»¹¿ÉÒÔµ¼³öÎı¾ÎļþµÈ¶àÖÖ¸ñʽ
ʵÀý:EXEC master..xp_cmdshell 'bcp saletesttmp.dbo.CusAccount out c:\temp1.xls -c -q -S"pmserver" -U"sa" -P"sa"'
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname from pubs..authors ORDER BY au_lname" queryout C:\ authors.xls -c -Sservername -Usa -Ppassword'
ÔÚVB6ÖÐÓ¦ÓÃADOµ¼³öEXCELÎļþ´úÂ룺
Dim cn As New ADODB.Connection
cn.open "Driver={SQL Server};Server=WEBSVR;DataBase=WebMis;UID=sa;WD=123;"
cn.execute "master..xp_cmdshell 'bcp "SELECT col1, col2 from ¿âÃû.dbo.±íÃû" queryout E:\DT.xls -c
Ïà¹ØÎĵµ£º
Êý¾ÝÀàÐÍÊÇÊý¾ÝµÄÒ»ÖÖÊôÐÔ£¬±íʾÊý¾ÝËù±íʾÐÅÏ¢µÄÀàÐÍ¡£ÈκÎÒ»ÖÖ¼ÆËã»úÓïÑÔ¶¼¶¨ÒåÁË×Ô¼ºµÄÊý¾ÝÀàÐÍ¡£µ±È»£¬²»Í¬µÄ³ÌÐòÓïÑÔ¶¼¾ßÓв»Í¬µÄÌص㣬Ëù¶¨ÒåµÄÊý¾ÝÀàÐ͵ĸ÷ÀàºÍÃû³Æ¶¼»ò¶à»òÉÙÓÐЩ²»Í¬¡£SQLServerÌṩÁË25ÖÖÊý¾ÝÀàÐÍ£º
¡¡¡¡·Binary[(n)]
¡¡¡¡·Varbinary[(n)]
¡¡¡¡·Char[(n)]
¡¡¡¡·V ......
--> Title : varbinaryת»»³É×Ö·û´®
--> Author : wufeng4552
--> Date : 2009-12-15
declare @s varchar(20),@bin varbinary(1000)
select @s='www.CSDN.net',@bin=cast(@s as varbinary(1000))
declare @re varchar(1000),@i int
select @re='',@i=datalength(@bin)
while @i>0
&n ......
ÈçͼËùʾ£¬ÔÚ°²È«ÐÔ-µÇ½Àï¿ÉÒÔ¿´µ½ÓÒ±ßÁбíÀïµÄÓû§£¬Ñ¡ÖÐÓû§ÓÒ¼ü-ÊôÐÔ¿ÉÒÔ¸ü¸ÄÓû§ÃÜÂ룬¼°Êý¾Ý¿â½ÇÉ«µÈ¡£
²é¿´Óû§Ãû£¬¼°ÃÜÂëÊÇ·ñÕýÈ·£¬¿ÉÒÔµ¥¶ÀµÇ½ ²éѯ·ÖÎöÆ÷
Èç¹ûÄܵǽ˵Ã÷ÉèÖÃÕýÈ·£¬ÔÚmssql´î½¨µÄasp cmsÀï¾³£ÒªÓõ½Óû§Ãû£¬ÃÜÂë¡£
ÏÖÔÚ¿´Ã¿¸öÊý¾ÝÏÂÃæµÄÓû§Ñ¡ÏÈçͼ
Ñ¡ÖÐÒ»¸öÒ»¸öÊý¾Ý¿â£¬»òÏÂÃæµÄÓû§Ñ ......