Count of rows in a flat-file
Hi, I have a situation I have a flat file in FTP Location. I want to find the number of rows in it using T-SQL instead of using rowcount in ssis. is there any way to find it. Thanks, Chakri
May 16th, 2011 7:39am

If you want to do it thru SSIS please check this http://www.programmersedge.com/?p=1492 T-SQL script here 1. select count(1) from <tableName> 2. sp_spaceused <tableName> hope this helps http://uk.linkedin.com/in/ramjaddu
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2011 8:01am

you need to download the file from FTP first, and then you can use these ways to get row count: 1- Import flat file into a database table, and get row count with t-sql with execute sql task 2- use data flow task to fetch number of rows with RowCount Transformation 3- use script task to get number of lines in the flat file. if you want to fetch just number of rows and you don't want to import data , I suggest #3 way , this is sample C# code to fetch number of rows in flat file : System.IO.File.ReadAllLines("path").Length http://www.rad.pasfu.com
May 16th, 2011 8:04am

Not sure if that's possible with T-SQL, but check the T-SQL forum: http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads Or you first have to download the file and add the rows to an database table. And do the count there... Alternatives: a Script Task with some code like this: long count = 0; using (StreamReader r = new StreamReader(@"C:\file.txt")) { string line; while ((line = r.ReadLine()) != null) { count++; } } or var count = 0; using (var reader = File.OpenText(@"C:\file.txt")) { while (reader.ReadLine() != null) { count++; } } Please mark the post as answered if it answers your question | My SSIS Blog: http://microsoft-ssis.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2011 8:12am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics