Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: Yesterday @ 1:08 PM
Points: 12,927, Visits: 32,333
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
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: Thursday, November 13, 2014 9:37 AM
Points: 160, Visits: 704
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: Wednesday, October 1, 2014 12:48 PM
Points: 135, Visits: 286
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: Wednesday, October 1, 2014 12:48 PM
Points: 135, Visits: 286
Nice package. Do you have the code posted some where?
Post #1441249
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse