从sql数据库中导出图片.doc

从sql数据库中导出图片.doc

ID:60811654

大小:14.50 KB

页数:4页

时间:2020-12-20

从sql数据库中导出图片.doc_第1页
从sql数据库中导出图片.doc_第2页
从sql数据库中导出图片.doc_第3页
从sql数据库中导出图片.doc_第4页
资源描述:

《从sql数据库中导出图片.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[p_export]')andOBJECTPROPERTY(id,N'IsProcedure')=1)dropprocedure[dbo].[p_export]GO  /*--导出表中的image列为文件  导出当前库,指定表中,指定的image/text/ntext列的数据为文件导出生成的文件以表中的主键做为文件名可以在指定导出目录时,指定文件的前缀导出处理采用了windows身份验证,如果你的sql不支持windows身份验证则需要把bcp处理语句中的/T,替换为/U"

2、sa"/P"sa的密码"--*/  /*--调用示例  --导出图像execp_export'pub_info','pub_id','logo'  --导出文本文件,文件名以pp开头execp_export'pub_info','pub_id','pr_info','c:pp_','.txt'--*/createprocp_export@tbnamesysname,--要进行导出处理的表名@keyfdsysname,--要进行导出处理的主键名@imgfdsysname,--要导出的图像字段名@pathnvarchar(1000)='c:',--导出的图像文件要保存的目录@filesysn

3、ame='',    --导出的图像文件扩展名,默认为.gif              --如果是.开头,表明是直接指定的扩展名              --否则表示从表中的该字段获取扩展名@whereandnvarchar(1000)=''--导出数据的条件asdeclare@fmtfilenvarchar(1000),@snvarchar(4000)ifisnull(@path,'')=''set@path='c:'  ifisnull(@file,'')=''set@file='.gif'  selecttop1@fmtfile=rtrim(reverse(filename))f

4、rommaster.dbo.sysfileswherename=N'master'select@fmtfile=stuff(@fmtfile,1,charindex('',@fmtfile),N''),@fmtfile=reverse(stuff(@fmtfile,1,charindex('',@fmtfile),N''))+N'BACKUP'+cast(newid()asnvarchar(36))+N'.fmt'set@s=N'bcp"selectnullunionallselect0unionallselect0unionallselectnullunionallselectnu

5、ll"'+N'queryout"'+@fmtfile+N'"/T/c'execmaster..xp_cmdshell@s,no_output  set@s=N'declaretbcursorlocalforselectN''bcp"select''+quotename(@imgfd)+''from''+quotename(db_name())+''..''+quotename(@tbname)+''where''+quotename(@keyfd)+''=''+rtrim(pub_id)+''"queryout"''+@path+rtrim(pub_id)+'+casewhenleft(@f

6、ile,1)='.'thenquotename(@file,'''')elseN'ltrim('+quotename(@file)+N')'end+N'+''"/T/i"''+@fmtfile+''"''from'+quotename(@tbname)+casewhenisnull(@whereand,'')=''then''elseN'where'+@whereandend+N'opentbfetchtbinto@swhile@@fetch_status=0beginexecmaster..xp_cmdshell@s--,no_outputfetchtbinto@sendclosetbde

7、allocatetb'execsp_executesql@s,N'@tbnamesysname,@keyfdsysname,@imgfdsysname,@pathnvarchar(1000),@filenvarchar(10),@fmtfilenvarchar(1000),@snvarchar(4000)',@tbname,@keyfd,@imgfd,@path,@file,@fmtfile,@sset@s=

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。