views:

43

answers:

3

I need to read in a log file created by a SSIS package in my stored procedure.

Is there a good way to do this?

I tried using this code but it shows the contents of my file as jibberish. Is there some kind of encoding issue it's not handling? Is there an easier way?

+3  A: 

Have you tried a straight bulk insert? For example:

create table #TempTable (line varchar(256))
bulk insert #TempTable from 'c:\logfile.txt'
Andomar
That works thanks!
Greg
+1  A: 

You can try

select * from OPENROWSET(BULK N'C:\logfile.txt', SINGLE_BLOB)
Denis Valeev
That gives me back a long string of numbers (hexadecimal without spaces maybe?)
Greg
It reads the whole file as a single blob. Whaddya expect? :) Then you can splice it and dice it with all kinds of string manipulation functions if you like.
Denis Valeev
A: 

Stored Procedures doing File Manipulation doesnt sound like a good idea!

Maybe you can explain the scenario in more detail that might help people suggest maybe a better way out.

However, if you HAVE TO, i think you should look at CLR Stored Procedures in SQL Server. That way, you can do the file manipulation using regular .NET classes

Refer these MSDN Link 1 and MSDN Link 2 links for more details

This particular link is related to permissions that need to be given to the assembly for it to be able to access external resources like files from a CLR procedure in SQL Server

InSane