Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count difference on tables

Status
Not open for further replies.

sds814

Programmer
Feb 18, 2008
164
US
On server A, when I do SELECT COUNT(*) FROM tblzCdCustomFieldLabels I get 574,228. On server B, when I do SELECT COUNT(*) FROM tblzCdCustomFieldLabels I get 2,533,100. So the difference being 1,958,872. However, when I do
Code:
SELECT *
FROM [A].databasename.dbo.tblzCdCustomFieldLabels prod
WHERE NOT EXISTS (SELECT * 				  FROM [B].databasename.dbo.tblzCdCustomFieldLabels dev
				  WHERE dev.eff_dt = prod.eff_dt AND dev.prod_ID = prod.prod_ID 
					AND dev.prodname_CD = prod.prodname_CD AND dev.CO_CD = prod.CO_CD)

I get the difference as 1,985,332. The 4 fields make up the primary key for the table tblzCdCustomFieldLabels. Shouldn't the difference be the same? Is the difference due to having more null values in the rows on server B?
 
If there are NULLs in any of the columns you are joining on, then the comparisons will evaluate to false and not give you the totals you expect
 
The columns that I'm joining on combine as the primary key so they couldn't have Null values.
 
Your query determines records that do not exist on another server, not the difference in totals.






 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top