| Mark's profileMark's spacePhotosBlogLists | Help |
|
March 26 两个存储过程,敝帚自珍create proc p_writefile
@filename varchar(1000),--要操作的文本文件名 @text varchar(8000) --要写入的内容 as declare @err int,@src varchar(255),@desc varchar(255) declare @obj int exec @err=sp_oacreate 'Scripting.FileSystemObject',@obj out if @err<>0 goto lberr exec @err=sp_oamethod @obj,'OpenTextFile',@obj out,@filename,8,1 if @err<>0 goto lberr exec @err=sp_oamethod @obj,'WriteLine',null,@text if @err<>0 goto lberr exec @err=sp_oadestroy @obj return lberr: exec sp_oageterrorinfo 0,@src out,@desc out select cast(@err as varbinary(4)) as 错误号 ,@src as 错误源,@desc as 错误描述 GO create proc p_getxiaozhangfile as --删除旧文件 exec master.dbo.xp_cmdshell 'del d:\xiaozhangfile\cmdfile\xiaozhangfile.txt' exec master.dbo.xp_cmdshell 'del d:\xiaozhangfile\cmdfile\xiaozhangfile.bat' --昨天的日期字符串 declare @yyyymmdd varchar(50) declare @int_yyyy int declare @int_mm int declare @int_dd int declare @char_yyyy varchar(50) declare @char_mm varchar(50) declare @char_dd varchar(50) declare @yesterday datetime set @yesterday=dateadd(dd,-1,getdate())
set @int_yyyy=year(@yesterday) set @int_mm=month(@yesterday) set @int_dd=day(@yesterday) set @char_yyyy=cast(@int_yyyy as varchar(50))
if @int_mm<10
set @char_mm='0'+cast(@int_mm as varchar(50)) else set @char_mm=cast(@int_mm as varchar(50)) if @int_dd<10 set @char_dd='0'+cast(@int_dd as varchar(50)) else set @char_dd=cast(@int_dd as varchar(50)) set @yyyymmdd=@char_yyyy+@char_mm+@char_dd
--select @yyyymmdd
--生成FTP.txt文件
declare @getftpfile varchar(50) set @getftpfile='get pyxz'+@yyyymmdd+'.txt' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt',帐号' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt','密码' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt','cd /home/bill4/tuxapp/myFile' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt','lcd d:\xiaozhangfile\downloadfile' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt',@getftpfile exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.txt','bye' --生成FTP.BAT文件 exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.bat','ftp -s:d:\xiaozhangfile\cmdfile\xiaozhangfile.txt 132.97.10.36' --覆盖目标文件 declare @copyfile varchar(100) set @copyfile='copy d:\xiaozhangfile\downloadfile\pyxz'+@yyyymmdd+'.txt d:\xiaozhangfile\targetfile\pyxz.txt' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.bat','del d:\xiaozhangfile\targetfile\pyxz.txt' exec p_writefile 'd:\xiaozhangfile\cmdfile\xiaozhangfile.bat', @copyfile exec master.dbo.xp_cmdshell 'd:\xiaozhangfile\cmdfile\xiaozhangfile.bat' --删除表 delete from pyxz --插入新数据 insert into pyxz (xz_date,tel,branch,busi_id,clien_type,total,xz_total,yf_total,jf_date,o_paymode,n_paymode,xz_no) SELECT ltrim(rtrim(xz_date)),ltrim(rtrim(tel)),ltrim(rtrim(branch)),ltrim(rtrim(busi_id)),ltrim(rtrim(clien_type)), cast(total as decimal(18,2)),cast(xz_total as decimal(18,2)),cast(yf_total as decimal(18,2)),ltrim(rtrim(jf_date)), ltrim(rtrim(o_paymode)),ltrim(rtrim(n_paymode)),ltrim(rtrim(xz_no)) FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="d:\xiaozhangfile\targetfile";Extended Properties=Text')...pyxz#txt --把新数据插入到历史记录表 delete from pyxz_his where xz_date in (select xz_date from pyxz) insert into pyxz_his(xz_date,tel,branch,busi_id,clien_type,total,xz_total,yf_total,jf_date,o_paymode,n_paymode,xz_no) select xz_date,tel,branch,busi_id,clien_type,total,xz_total,yf_total,jf_date,o_paymode,n_paymode,xz_no from pyxz GO March 12 use of Schema.ini FileSchema.ini File (Text File Driver)When the Text driver is used, the format of the text file is determined by using a schema information file. The schema information file, which is always named Schema.ini and always kept in the same directory as the text data source, provides the IISAM with information about the general format of the file, the column name and data type information, and a number of other data characteristics. A Schema.ini file is always required for accessing fixed-length data; you should use a Schema.ini file when your text table contains DateTime, Currency, or Decimal data or any time you want more control over the handling of the data in the table. Note The Text ISAM will obtain initial values from the registry, not from Schema.ini. The same default file format applies to all new text data tables. All files created by the CREATE TABLE statement inherit those same default format values, which are set by selecting file format values in the Define Text Format dialog box with <default> chosen in the Tables list. If the values in the registry are different from the values in Schema.ini, the values in the registry will be overwritten by the values from Schema.ini. Understanding Schema.ini FilesSchema.ini files provide schema information about the records in a text file. Each Schema.ini entry specifies one of five characteristics of the table:
The following sections discuss these characteristics. Specifying the File NameThe first entry in Schema.ini is always the name of the text source file enclosed in square brackets. The following example illustrates the entry for the file Sample.txt: [Sample.txt] Specifying the File FormatThe Format option in Schema.ini specifies the format of the text file. The Text IISAM can read the format automatically from most character-delimited files. You can use any single character as a delimiter in the file except the double quotation mark ("). The Format setting in Schema.ini overrides the setting in the Windows Registry on a file-by-file basis. The following table lists the valid values for the Format option.
Specifying the FieldsYou can specify field names in a character-delimited text file in two ways:
You must specify each column by number and designate the column name, data type, and width for fixed-length files. Note The ColNameHeader setting in Schema.ini overrides the FirstRowHasNames setting in the Windows Registry on a file-by-file basis. The data types of the fields can also be determined. Use the MaxScanRows option to indicate how many rows should be scanned when determining the column types. If you set MaxScanRows to 0, the entire file is scanned. The MaxScanRows setting in Schema.ini overrides the setting in the Windows Registry on a file-by-file basis. The following entry indicates that Microsoft Jet should use the data in the first row of the table to determine field names and should examine the entire file to determine the data types used: ColNameHeader=True MaxScanRows=0 The next entry designates fields in a table by using the column number (Coln) option, which is optional for character-delimited files and required for fixed-length files. The example shows the Schema.ini entries for two fields, a 10-character CustomerNumber text field and a 30-character CustomerName text field: Col1=CustomerNumber Text Width 10 Col2=CustomerName Text Width 30 The syntax of Coln is: Coln=ColumnName type [Width #] The following table describes each part of the Coln entry.
Selecting a Character SetYou can select from two character sets: ANSI and OEM. The CharacterSet setting in Schema.ini overrides the setting in the Windows Registry on a file-by-file basis. The following example shows the Schema.ini entry that sets the character set to ANSI: CharacterSet=ANSI Specifying Data Type Formats and ConversionsThe Schema.ini file contains a number of options that you can use to specify how data is converted or displayed. The following table lists each of these options.
Note If you omit an entry, the default value in the Windows Control Panel is used. |
|
|