SQL Serverµ¼³öEXCELµÄ´æ´¢¹ý³Ì
--sqlÓï¾ä¾ÍÓÃÏÂÃæµÄ´æ´¢¹ý³Ì
/*--Êý¾Ýµ¼³öExcel
µ¼³ö²éѯÖеÄÊý¾Ýµ½Excel,°üº¬×Ö¶ÎÃû,ÎļþΪÕæÕýµÄExcelÎļþ
,Èç¹ûÎļþ²»´æÔÚ,½«×Ô¶¯´´½¨Îļþ
,Èç¹û±í²»´æÔÚ,½«×Ô¶¯´´½¨±í
»ùÓÚͨÓÃÐÔ¿¼ÂÇ,½öÖ§³Öµ¼³ö±ê×¼Êý¾ÝÀàÐÍ
--×Þ½¨ 2003.10--*/
/*--µ÷ÓÃʾÀý
p_exporttb @sqlstr='select * from µØÇø×ÊÁÏ'
,@path='c:\',@fname='aa.xls',@sheetname='µØÇø×ÊÁÏ'
--*/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_exporttb]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_exporttb]
GO
create proc p_exporttb
@sqlstr sysname, --²éѯÓï¾ä,Èç¹û²éѯÓï¾äÖÐʹÓÃÁËorder by ,Çë¼ÓÉÏtop 100 percent
@path nvarchar(1000), --Îļþ´æ·ÅĿ¼
@fname nvarchar(250), --ÎļþÃû
@sheetname varchar(250)='' --Òª´´½¨µÄ¹¤×÷±íÃû,ĬÈÏΪÎļþÃû
as
declare @err int,@src nvarchar(255),@desc nvarchar(255),@out int
declare @obj int,@constr nvarchar(1000),@sql varchar(8000),@fdlist varchar(8000)
--²ÎÊý¼ì²â
if isnull(@fname,'')='' set @fname='temp.xls'
if isnull(@sheetname,'')='' set @sheetname=replace(@fname,'.','#')
--¼ì²éÎļþÊÇ·ñÒѾ´æÔÚ
if right(@path,1)<>'\' set @path=@path+'\'
create table #tb(a bit,b bit,c bit)
set @sql=@path+@fname
insert into #tb exec master..xp_fileexist @sql
--Êý¾Ý¿â´´½¨Óï¾ä
set @sql=@path+@fname
if exists(select 1 from #tb where a=1)
set @constr='DRIVER={Microsoft Excel Driver (*.xls)};DSN='''';READONLY=FALSE'
+';CREATE_DB="'+@sql+'";DBQ='+@sql
else
set @constr='Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties="Excel 5.0;HDR=YES'
+';DATABASE='+@sql+'"'
-
Ïà¹ØÎĵµ£º
Ê×ÏȾÍÊÇÒª×Ô¼º±àдһ¶Î´úÂ룬´æΪ.stx
Îļþ£¨ÀýÈçsql.stx£©£¬È»ºóÔÚeditplusµÄ²Ëµ¥À¸Tools->Configure User
Tools->Files->Setting &syntax,µãadd°´Å¥£¬ÔÚdescriptionÀ¸Î»ÌîÉÏsql,file
ExtensionsÀ¸Î»Ò²ÌîÉÏsql,Èç¹ûÓжà¸öÀ©Õ¹Ãû£¬Ö®¼äÓÓ£»”¸ô¿ª£¨ÀýÈ磺sql;db2£©,È»ºóÔÚsyntax
fileÀ¸Î»ÌîÉ ......
¼ÙÈçÄãд¹ýºÜ¶à³ÌÐò£¬Äã¿ÉÄÜż¶û»áÅöµ½ÒªÈ·¶¨×Ö·û»ò×Ö·û´Ü´®·ñ°üº¬ÔÚÒ»¶ÎÎÄ×ÖÖУ¬ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«ÌÖÂÛʹÓÃCHARINDEXºÍPATINDEXº¯ÊýÀ´ËÑË÷ÎÄ×ÖÁкÍ×Ö·û´®¡£ÎÒ½«¸æËßÄãÕâÁ½¸öº¯ÊýÊÇÈçºÎÔËתµÄ£¬½âÊÍËûÃǵÄÇø±ð¡£Í¬Ê±ÌṩһЩÀý×Ó£¬Í¨¹ýÕâЩÀý×Ó£¬Äã¿ÉÒÔ¿ÉÒÔ¿¼ÂÇʹÓÃÕâÁ½¸öº¯ÊýÀ´½â¾öºÜ¶à²»Í¬µÄ×Ö·ûËÑË÷µÄÎÊÌâ¡£
&nb ......
Ò»¡¢Êý¾Ý¿âÉè¼Æ·½Ãæ
1¡¢×Ö¶ÎÀàÐÍ¡£
varchar(max)\nvarchar(max)ÀàÐ͵ÄÒýÈë´ó´óµÄÌá¸ßÁ˱à³ÌµÄЧÂÊ£¬¿ÉÒÔʹÓÃ×Ö·û´®º¯Êý¶ÔCLOBÀàÐͽøÐвÙ×÷£¬ÕâÊÇÒ»¸öÁÁµã¡£µ«ÊÇÕâ¾ÍÒý·¢Á˶ÔvarcharºÍcharЧÂÊÌÖÂÛµÄÀÏÎÊÌâ¡£µ½µ×ÈçºÎ·ÖÅävarcharµÄÊý¾Ý£¬ÊÇ·ñ»á³öÏÖ´ó¹æÄ£µÄËéƬ£¿ÊÇ·ñËéƬ»áÒý·¢Ð§ÂÊÎÊÌ⣿ÕⶼÊÇÐèÒª½øÒ»²½Ì½ÌֵĶ«Î÷¡£
v ......
ÎÊÌâ
¡¡¡¡µ±sql serverÆô¶¯Ê±£¬ÎÒºÜÏëÔËÐÐÒ»¸ö´æ´¢¹ý³Ì¡£ÓÐûÓÐÒ»ÖÖ·½·¨¿ÉÒÔÔÚÿ´ÎSQL Server·þÎñÆô¶¯Ê±¶¼»á×Ô¶¯Ö´ÐÐÕâ¸ö´æ´¢¹ý³ÌÄØ?
¡¡¡¡×¨¼Ò½â´ð
¡¡¡¡sql ServerÌṩÁËϵͳ´æ´¢¹ý³Ìsp_procoption£¬Õâ¸ö´æ´¢¹ý³Ì¿ÉÒÔÓÃÓÚµ±SQL Server·þÎñÆô¶¯Ê±Ö¸ÅÉÒ»¸ö»òÕ߶à¸ö´æ´¢¹ý³Ì×Ô¶¯Ö´ÐС£ÕâÊÇÒ»¸öºÜ²»´íµÄÑ¡Ôñ£¬Ëü¿ÉÒÔÓÃÓÚ¶àÖÖ ......