Click here to Skip to main content
15,887,421 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Just want to right a stored procedure, that will read six column from .txt file and then insert into temp table , than i have to do some transformation on data , than i want to write this data back in to four files

so i have a column whos values are A,B,C,D so i have to write 4 files and i want to run this from job agent which is not a problem , and is there a way in stored procedure to directly read or paste file from ftp server

Please any help would be much appriciated


Thanks
Posted
Comments
saad88 2-Apr-15 10:18am    
so columns are email,address,cell,type,version .... so i have to add version column by my self ..... so any rough code idea would be much appriciated , the scope of project is to take invalid data out and insert few things in , i have Pentaho ETL but i am looking for stored procedure

1 solution

Hey,
I've two set of codes which might help you to resolve the issue.
First one is to read the Data from a Text File.
SQL
--Create a linked server.
EXEC sp_addlinkedserver txtsrv, N'Jet 4.0', 
   N'Microsoft.Jet.OLEDB.4.0',
   N'c:\data\',
   NULL,
   N'Text';
GO

----Set up login mappings.
EXEC sp_addlinkedsrvlogin txtsrv, FALSE, sa, NULL;
GO

--List the tables in the linked server.
EXEC sp_tables_ex txtsrv;
GO

--Query one of the tables: file1#txt
--using a four-part name. 
SELECT * 
FROM txtsrv...[distqry#txt];

Now you'll get the data in a table and that you can copy to a temp table. Process it however you wanted and create the text
and Here is another set of code to write text Data into a file and create a file from SQL Server.
SQL
DECLARE @Text AS VARCHAR(100)
DECLARE @Cmd AS VARCHAR(100)
SET @Text = 'Hello world'
SET @Cmd ='echo ' +  @Text + ' > e:\AppTextFile.txt'
print @cmd
EXECUTE Master.dbo.xp_CmdShell  @Cmd
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900