SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Access Query ported to SQL


Access Query ported to SQL

Author
Message
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63771 Visits: 17974
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 Modens 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)
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 49
Sorry, feel free to delete the redundant posts.
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)SSC Guru (63K reputation)

Group: General Forum Members
Points: 63771 Visits: 17974
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 Modens 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)
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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
realvilla
realvilla
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search