SQL Server 2008: trying to export my data to xls file and data not displaying in rows -


i have sql query wich imports data csv file , matches data records on database make sure records exist, when thats done exports file xls file, when export file result set outputs in single line insted of rows imported. eg. imported rows 10, matched 7. exported rows 1 intead of 7:

drop table csvdataraw,#filelist,#tmpid/#failures,#success,/ --,#reversefile

    if not exists (select * sys.tables name = 'csvdataraw')     begin      create table csvdataraw     (          cellnumber varchar(12),     sms_msg varchar(250)      )     end      create table #filelist (      smsfilename varchar(512))       declare @path varchar(256) = 'dir c:\fileimport\inbox\'     declare @command varchar(1024) =  @path+' /a-d  /b'      --print @command      insert #filelist      exec master.dbo.xp_cmdshell @command     delete #filelist  smsfilename null       declare @file varchar (255) =      ( select top 1 * #filelist     smsfilename 'sms%')      print @file      declare @smsfilename varchar (255)     set @smsfilename = 'c:\fileimport\inbox\'     set @smsfilename = @smsfilename + @file -- + ''''       declare @bulkinsert varchar(max);      set @bulkinsert = 'bulk insert [csvdataraw]      ' + char(39) + @smsfilename +char(39)+     ' (rowterminator = ''\n'', fieldterminator = '','', firstrow = 1)'     --print @bulkinsert      exec(@bulkinsert)      alter table csvdataraw add id int identity     go       alter table csvdataraw add matterno varchar (50)      go     update csvdataraw set matterno = (select top 1 h_mid history h_phonenumber = csvdataraw.cellnumber)     go      alter table csvdataraw add h_description varchar(50)      go     update csvdataraw set h_description = (select top 1 h_idx history (nolock) h_description = csvdataraw.sms_msg)      go      delete csvdataraw matterno null      create table #tmpid     (       id int,       note varchar(255)     )      declare @line varchar(max)     declare @filename varchar(255)     declare @row int      --insert header     set @filename = 'c:\fileimport\sms_history_' + replace(replace(replace(convert(varchar,getdate(),120),' ',''),'-',''),':','')  + '.xls'     set @line = 'profile=0,product=0,client=0,importtype=20,delimiter= ,' + char(13) + char(10)      delete #tmpid      insert #tmpid (id, note)     select cellnumber, sms_msg     csvdataraw       select @line = @line + note #tmpid     --print @line     exec dbo.uspwritetofile @filename, @line     --print @line     drop table csvdataraw,#tmpid,#filelist      create table #filelist (      smsfilename varchar(512))     declare @path varchar(256) = 'dir c:\fileimport\inbox\'     declare @command varchar(1024) =  @path+' /a-d  /b'      insert #filelist      exec master.dbo.xp_cmdshell @command     delete #filelist  smsfilename null       declare @file varchar (255) =      (select top 1 * #filelist     smsfilename 'sms%')      print @file      declare @smsfilename varchar (255)     set @smsfilename = 'move /y c:\fileimport\inbox\ c:\fileimport\archive\' --here setting variable     set @smsfilename = @smsfilename + @file  + ''''      exec xp_cmdshell 'move /y c:\fileimport\inbox\ c:\fileimport\archive' --this part moving file      drop table #filelist 


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -