realvilla (6/27/2013)
Sean, here is the "unsolved mystery". When I run your program pretty much as written, I get about 70,000 rows that don't update (null Return dates). Included in those rows is the following grouping.Yet when I tag this code right after where v.RowNum <= r.UnitCount, I get 623 records for VehiclesToUdate, ReturnsPros and VehicleDetail the way I should.
How can this be?
Select count(*) as UpdateCount, 'Update' as SQLName from VehiclesToUpdate Where Region='Central' And ProgYear='13' And LeaseCycle='1'And ModelName='FUSION I4 SE' And MFG='FRD' And RiskNonRiskFlag='R'
GO
Select Sum(UnitCount) as ReturnsCount, 'RCount' as SQLName from ReturnsPros Where Region='Central' And ProgYear='13' And LeaseCycle='1'And ModelName='FUSION I4 SE' And MFG='FRD' And RiskNonRiskFlag='R'
GO
Select count(*) as VDCount, 'Detail' as SQLName from VehicleDetail Where Region='Central' And ProgYear='13' And LeaseCycle='1'And ModelName='FUSION I4 SE' And MFG='FRD' And RiskNonRiskFlag='R'
GO
Wow this is going to be tough to figure out from here without a sample dataset where we can reproduce this. Can you make a smaller dataset where this issue occurs? It has been several days since I looked this in detail and don't really remember all the details. It will take me a bit to get back up to speed and I am swamped at work right now. I will try to get back here early next week and see what is happening. Sorry I can't help much more right now.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/