Office中国论坛/Access中国论坛
标题:
关于导出Linux格式txt
[打印本页]
作者:
roych
时间:
2018-11-1 15:43
标题:
关于导出Linux格式txt
默认情况下,SQL Server导出的数据是CRLF换行的(相当于\n\r),但一些Linux下的数据库对含有换行符的数据比较敏感,导入后可能会出现一些意想不到的问题。 之前我一般是导出后,用notepad++打开,再转为Linux格式保存的。后来在官网上发现有导出Linux格式文本文件的帮助说明,于是写了这个存储过程。不敢专美,现在贴出来,供需要的版友使用。存储过程的目的是导出一个以日期作为条件的查询到文本文件里。新手请注意里面多个引号的使用。
CREATE proc [dbo].[outputNumber]
as begin
declare @startDate date
--使用长日期
declare @startDateTime datetime
declare @endDateTime datetime
--使用条件
declare @strStart varchar(21)
declare @strEnd varchar(21)
--拼接SQL导出语句
declare @strSQL varchar(1000)
--获取上月日期
set @startDate=DATEADD(DAY,1-day(getdate()),getdate())
set @startDateTime=DATEADD(MONTH,-1,@startDate)
set @endDateTime=DATEADD(MILLISECOND,-3,convert(datetime,@startdate))
set @strEnd = convert(varchar(21),GETDATE(),120)
set @strStart= convert(varchar(21),@startDateTime,120)
set @strSQL='bcp "select distinct RIGHT(Destination,11) called from A9.dbo.bmdcallcenterrecord where StartTime between '''
set @strSQL =@strSQL+@strStart+''' and '''+ @strEnd+''' and ((len(Destination)=11 and Destination like''1%'')'
set @strSQL =@strSQL+ ' or (len(Destination)=12 and Destination like ''01%''))"'
set @strSQL =@strSQL+' queryout "G:\FTP_file\业支\tblCalled.txt" -c -r 0x0A -S"192.168.101.28" -U"sa" -P"Admin@123"'
--print @strSQL
EXEC master..xp_cmdshell @strSQL
END
复制代码
作者:
tmtony
时间:
2018-11-1 16:16
肉一,最近高产啊,赞一个!
作者:
roych
时间:
2018-11-1 16:40
tmtony 发表于 2018-11-1 16:16
肉一,最近高产啊,赞一个!
最近刚好没那么忙,就到论坛上拔拔草。看到一些问题,感觉实际工作中可能会遇到,就统一整理成帖子发出,供大家参考了。
蜀中无大将,廖化作先锋。
山中无老虎,猴子当王。
趁其他版主、大神都在沉寂,我就来刷下存在感,混个脸熟吧。
作者:
access新新新手
时间:
2018-11-1 17:56
谢谢分享
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3