¸ß·ÖÇósqlserverдexcel - MS-SQL Server / ÒÉÄÑÎÊÌâ
1.Ôõô°ÑÊý¾Ý´ÓsqlserverÀïÃæµÄÊý¾ÝдÈëµ½Ö¸¶¨Â·¾¶µÄexcel
±ÈÈç
declare @¹«Ë¾Ãû³Æ char(50)
set @¹«Ë¾Ãû³Æ = (select ¹«Ë¾Ãû³Æ from ¹«Ë¾ÐÅÏ¢)
EXEC [master]..xp_cmdshell 'bcp "select * from [master].tab_a" queryout D:\'+ convert(varchar,@¹«Ë¾Ãû³Æ)+'\ssss.xls -c -q -S"." -U"sa" -P"123456"'
µ«ÊÇ×ÜÊDZ¨
ÏûÏ¢ 102£¬¼¶±ð 15£¬×´Ì¬ 1£¬µÚ 68 ÐÐ
'+' ¸½½üÓÐÓï·¨´íÎó¡£
ÎÒÓÃÏÂÃæÓï¾äÒ²±¨Í¬ÑùµÄ´íÎó
insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 8.0;IMEX=0;HDR=YES;DATABASE=d:\'+convert(varchar,rtrim(@¹«Ë¾Ãû³Æ))+'\ssss.xls',[Sheet1$])
select * from tab_a
2¡¢ÈçºÎÔÚÉÏÒ»¾äµÄ»ù´¡ÉϽ«½á¹û²åÈëµ½Ö¸¶¨µÄµ¥Ôª¸ñÄÚ
±ÈÈçÎÒÒª½«Êý¾Ýдµ½ssss.xls£¬sheet1µÄB3µ¥Ôª¸ñÄÚ
лл¸÷λ´óÏÀ
Ïà¹ØÎÊ´ð£º
ÎÒÒ»¸öÏîÄ¿£¬Óиö²åÈë²Ù×÷£¬¾ßÌåÊÇÕâÑùµÄ£º
ÎÒÓнø»õÐÅÏ¢±í¡£ÔÚ³ö»õʱѡÔñÏàÓ¦µÄ½ø»õÐÅÏ¢£¬ÊäÈëÊýÁ¿£¬Ñ¡Ôñ²¿Ãź󣬵㱣´æ°´Å¥£¬ÓÉÓÚÍøÂçÑÓʱ£¬µãÒ»ÏÂûÓз´Ó³£¬ÓÚÊÇÓû§¾ÍÓÖµãһϣ¬µ¼ÖÂÒ»´Î²åÈëÁËÁ½Ìõ¼Ç¼:
Àý£º
......
ÎÒÓÐÒ»¸ö±í£¬½á¹¹ÊÇÕâÑù¡£
ת³ö µ¥Î» תÈ뵥λ ±ÊÊý ½ð¶î
date(Ö÷) outid(Ö÷) inid(Ö÷) num amt
2009 1 2 1 500 Ϊ 1 µ¥Î» ÔÚ2009Ä ......
½ñÌì×öÁËÒ»¸ö´æ´¢¹ý³Ì »·¾³ÊÇSQL2000Êý¾Ý¿â
´óÖÂÈçÏÂ
½¨Á¢ÁÙʱ±í
¶¨ÒåÔ±¹¤Óαê
Ñ»·Ô±¹¤£¨ÊôÓÚ1¸ö¹«Ë¾)
......
µÚÒ»¾ä:
select ht.gfdm,gfdm.gfmc,gfdm.lb ,sum(jh.htdj*jh.htsl)as je
from ht left join gfdm on ht.gfdm=gfdm.gfdm
join jh on ht.htbh=jh.hth
and ht.htbh not like'del%' and ht. ......
1¡£ÔõÑùʹxp_cmdshellÄÜÍêÕûÊä³ö³¬¹ý255¸ö×Ö·ûµÄ×Ö·û´®¡£
2¡£select ʱ£¬¼ìË÷ËÙ¶ÈÊÇÓëfromºóµÄ TABLE˳ÐòÓйأ¬»¹ÊÇÓëwhereÌõ¼þµÄ˳ÐòÓйØ(TABLEÊý¾Ý¶àÉÙ )
ÔÚϵͳÊôÐÔÉ趨ÀïÓиöÑ¡Ïî,¿ÉÒÔÐ޸ĵ¥×Ö¶ÎÊä³ö×ÖÊýÏÞÖÆ. ......