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 «««23456»»»

Access Query ported to SQL Expand / Collapse
Author
Message
Posted Friday, June 21, 2013 7:48 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
There shouldn't be any null records in the serial number column. But you made a good point. The join was wrong. It should have been:

Where VehiclesToUpdate.SerialNumber is null. When I did that, 157,511 records came up. But there seemed to be no rhyme or reason for these. I'll do some more invesitgation.

As for the stats. 209,809 total records in VD. Only 177,303 records came up in the VehiclesToUpdate. That leaves 32,506 not 157,511. We may be dealing with duplicates, which I will also investigate and let you know.
Post #1466191
Posted Friday, June 21, 2013 8:33 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
As far as I know, there are no null Serial Numbers. However, your reply made me take another look at the query and I should have typed:

Where VehiclesToUpdate.SerialNumber Is Null

When I did that, I returned 157,511 records. I assume these are VINs that are not in the VehiclesToUpdate that should be.

As for stats, there are 209,809 records in the VD table. VehiclesToUpdate returns 177,303 records which leaves 32,506 - NOT 157,511. The next thing I will check is duplicates. That could account for some records, but probably not that many.
Post #1466217
Posted Friday, June 21, 2013 8:55 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 13,080, Visits: 11,916
grovelli-262555 (6/20/2013)
I'm well versed in Access but know very little T-SQL. What does "ROW_NUMBER() over(partition by" do?


Here is entry from BOL: http://msdn.microsoft.com/en-us/library/ms186734.aspx


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1466229
Posted Friday, June 21, 2013 8:58 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
As far as I know, there are no nulls in the Serial Number column. You do bring up a good point though. I took another look at my criterion for the query and discovered that I should have typed:

Where VehiclesToUpdate.SerialNumber Is Null rather than where VehicleDetail.Serial.Number Is Null. When I executed it this way, I returned 157,511.

As for the stats, total records in the VehicleDetail are 209,809. However VehiclesToUpdate returns 177,303 which leaves 32,506 NOT 157,511.

This is my third attempt to post. I hope it works this time.
Post #1466232
Posted Friday, June 21, 2013 8:59 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
As far as I know, there are no nulls in the Serial Number column. You do bring up a good point though. I took another look at my criterion for the query and discovered that I should have typed:

Where VehiclesToUpdate.SerialNumber Is Null rather than where VehicleDetail.Serial.Number Is Null. When I executed it this way, I returned 157,511.

As for the stats, total records in the VehicleDetail are 209,809. However VehiclesToUpdate returns 177,303 which leaves 32,506 NOT 157,511.

This is my third attempt to post. I hope it works this time.
Post #1466234
Posted Friday, June 21, 2013 9:05 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
Sorry, feel free to delete the redundant posts.
Post #1466241
Posted Friday, June 21, 2013 1:39 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
Sean, you may not be there today but I made an interesting discovery. I tried four groupings for totals. For example, I took the group represented by:

Select *
From VehiclesToUpdate
Where Region='Central' And ProgYear='13' And RiskNonriskFlag='R' And MFG = 'MIT' And LeaseCycle='1' And ModelName='LANCER'

...and I got 202 units. Then taking that same grouping I tried adding the UnitCount in the RetrunsPros. Guess what. 202 units. I tried this for three other groups and they all matched perfectly. Then I tried it for the total unit count and they didn't match, but that could be explained by the gap cars (source='G') I'm getting closer. I thought you would like to hear the good news.
Post #1466376
Posted Friday, June 21, 2013 1:52 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 13,080, Visits: 11,916
realvilla (6/21/2013)
Sean, you may not be there today but I made an interesting discovery. I tried four groupings for totals. For example, I took the group represented by:

Select *
From VehiclesToUpdate
Where Region='Central' And ProgYear='13' And RiskNonriskFlag='R' And MFG = 'MIT' And LeaseCycle='1' And ModelName='LANCER'

...and I got 202 units. Then taking that same grouping I tried adding the UnitCount in the RetrunsPros. Guess what. 202 units. I tried this for three other groups and they all matched perfectly. Then I tried it for the total unit count and they didn't match, but that could be explained by the gap cars (source='G') I'm getting closer. I thought you would like to hear the good news.


That is good news. Sounds like you are pretty close to having it figured out.


_______________________________________________________________

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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1466381
Posted Wednesday, June 26, 2013 9:23 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
Sean, my question is - if the VehiclesToUpdate is obtained from the partitions in the VehicleDetail, why wouldn't they match the VehicleDetail? As you can see from the results, there are not enough cars to satisfy what was stipulated for returns.

Select count(*), 'Update' as SQLName from VehiclesToUpdate Where Region='Southeast' And ProgYear='12' And LeaseCycle='1'And ModelName='ALTIMA S' And MFG='NIS' And RiskNonRiskFlag='R'

GO

Select Sum(UnitCount), 'RCount' as SQLName from ReturnsPros Where Region='Southeast' And ProgYear='12' And LeaseCycle='1'And ModelName='ALTIMA S' And MFG='NIS' And RiskNonRiskFlag='R'

GO

Select count(*), 'Detail' as SQLName from VehicleDetail Where Region='Southeast' And ProgYear='12' And LeaseCycle='1'And ModelName='ALTIMA S' And MFG='NIS' And RiskNonRiskFlag='R'

GO

The results were:
101 for VehiclesToUpate
101 setup from ReturnsPros
46 in VehicleDetail




Post #1467737
Posted Wednesday, June 26, 2013 1:07 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 9:08 AM
Points: 35, Visits: 49
Sean, I devised a VBA procedure that creates SQL Code. I tried running the code below and look at the results following.

Select count(*), 'Update' as SQLName from VehiclesToUpdate Where Region='Central' And ProgYear='12' And LeaseCycle='1'And ModelName='GRCHEROKE LAR 4' And MFG='CHR' And RiskNonRiskFlag='R'
GO

Select Sum(UnitCount), 'RCount' as SQLName from ReturnsPros Where Region='Central' And ProgYear='12' And LeaseCycle='1'And ModelName='GRCHEROKE LAR 4' And MFG='CHR' And RiskNonRiskFlag='R'

GO

Select count(*), 'Detail' as SQLName from VehicleDetail Where Region='Central' And ProgYear='12' And LeaseCycle='1'And ModelName='GRCHEROKE LAR 4' And MFG='CHR' And RiskNonRiskFlag='R'

GO

VehiclesToUpdate: 101
ReturnsPros: 101
VehicleDetail: 46

I'm trying to think of a way to change VehiclesToUpdate. There are obvioiusly not enough records to accomodate ReturnsPros.
Post #1467825
« Prev Topic | Next Topic »

Add to briefcase «««23456»»»

Permissions Expand / Collapse