All the rows from my query result into a text field

hello Guys,

I have a Query that results me 130.000 rows, I need to save all the rows into a txt file.
Today I use my system to do that, row by row and it takes me almost 3 horas processing.
Is there any possibility to have all the rows into a text field, thus I could save all the information
into a file in seconds.

Regards
Alexandre
Khan ConsultoriaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
Check this article if this is what you need
Khan ConsultoriaAuthor Commented:
Hi John,

I can't do this way, I need to return the information to my system as result into a dataset.

I was thinking about this, for exemplo. But I think it will not be fast

create procedure sp_SPED_Livro_G_Diario_Geral
begin 
  SELECT newid() as chave, 'N' as lido, * into #tmp FROM E001_2018_SPED_Livro_G_Diario_Geral a where 1=1  and (periodo in ('2018') or left(periodo,6) between '201801' and '201812') order by ORDEM_1,ORDEM_2,registro
 
  create table #t(id int, texto text)

  insert into #t (id, texto) values (1, '')

  declare @chave varchar(200);
  declare @linha varchar(1000);

  while exists (select top 1 'x' from #t where lido='N')
  Begin 
    select top 1 @chave=chave, @linha=registro from #tmp where lido='N';
    update #t set texto=texto + @linha where id=1
    update #tmp set lido='S' where chave=@chave
  End

  select * from #t
end

Open in new window


my first problem over there is using text field :(
Khan ConsultoriaAuthor Commented:
I found a solution, as you can see bellow, the query return to my dataset in my application a text with all lines generated.


SELECT A.* 
			     FROM ( Select convert(text,     
							 REPLACE(  REPLACE(	 REPLACE(  REPLACE(  
																	(SELECT registro FROM E001_2018_SPED_Livro_G_Diario_Geral where periodo in ('2018') order by ORDEM_1, ORDEM_2, registro FOR XML PATH ('')) 
														   , '<registro>', '')  
												 , '</registro>', CHAR(13) + CHAR(10))
										 , '&#x0D;', '')
									  , '&lt;LINHAS&gt;', (SELECT convert(varchar, count(1)) FROM E001_2018_SPED_Livro_G_Diario_Geral where periodo in ('2018') ))) 
   				 AS LINHA ) AS A 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.