September 16, 2011 at 3:37 am
Hi,
I have a queries to read a simple text file. I want to read only end of line at that file. Because if i start read one by one it is taking long time to reach end of line. Because the file size is big. is there any way to go or read the end of line only.
Thanks
Vaithilingam.K
September 20, 2011 at 12:15 am
Hi,
See this thread.
http://stackoverflow.com/questions/2007857/reading-a-text-file-with-sql-server
Shatrughna
September 20, 2011 at 1:38 pm
You can use tail.exe. Microsoft released a version in the Windows Server 2003 Resource Kit and it works on Server 2008 as well: http://www.microsoft.com/download/en/details.aspx?id=17657
Or you can get an open source port of Unix tail for Windows: http://tailforwin32.sourceforge.net/[/url]
Both versions have an option to get n-lines starting from the end of the file and they can output the data to stdout. By executing tail using xp_CmdShell and inserting the output into a table you can easily get the last line of the file in very short order. Note that this requires you enable xp_CmdShell, which I recommend against.
I prefer to execute file handling tasks outside the SQL Server programming domain. Coupling your file handling to your database processing presents itself as a muddled application design.
How about this...create a SQL Agent Job with steps:
1. CmdExec step: Call a PowerShell script that leverages tail.exe to read the last line of the text file and store that line in a staging table in SQL Server.
2. T-SQL step: Call a Stored Procedure that will use the data from the file you just stored in a staging table.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply