Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Row count difference between flat file source and sql table Expand / Collapse
Author
Message
Posted Thursday, April 11, 2013 7:10 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:42 PM
Points: 14,445, Visits: 37,858
DevDB (4/11/2013)
Look for the line breaks in the export. That will cause the difference in count.


excellent point, something like this would be five rows in a text editor, but one row of data, if the row terminator was \n or some other custom terminator
'A string{cr}
with Carriage Returns{cr}
that finally ends {cr}
with a{cr}
{cr}{lf}'


Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1441228
Posted Thursday, April 11, 2013 7:18 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, January 13, 2015 9:11 AM
Points: 166, Visits: 733
Line breaks meaning carriage returns. I have an SSIS package that dumps out tables from a database into flat files and I have to verify the counts in the files match the table sizes. My package creates SQL statements for each table. For each field that is of type char, varchar, text, etc., I replace the carriage returns with some other marker. (We use ^^).

The query for a single table looks like:

select field1, replace(field2, Chr(13) & char(10), '^^'), field3...from myTable

The package then opens up each sql statement and a single script task generates the output data (as opposed to using a data flow task).

Just to be thorough, once the output files are created I have another script task that opens each one, counts the lines and compares the line count to what is expected. If a line count is off for a single file the package fails and my log table has an entry indicating which file's count was off.
Post #1441233
Posted Thursday, April 11, 2013 7:32 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 1, 2016 2:05 PM
Points: 154, Visits: 347
Mystery solved: I was not getting an accurate row count using
select APPNUMBER = COUNT(*) from SCORECARDAPP_TEST _new

When querying the dmv I was able to get the exact count as the flat file.

SELECT SUM (row_count)
FROM sys.dm_db_partition_stats
WHERE object_id=OBJECT_ID('SCORECARDAPP_TEST_new')
AND (index_id=0 or index_id=1);

Thanks Everyone!

Doug
Post #1441245
Posted Thursday, April 11, 2013 7:34 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 1, 2016 2:05 PM
Points: 154, Visits: 347
Nice package. Do you have the code posted some where?
Post #1441249
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse