We help IT Professionals succeed at work.
Get Started

Query to update fields with data from table rows above with the same dwelling type

AndyC1000
AndyC1000 asked
on
44 Views
Last Modified: 2015-12-07
Dear all,

I posted a similar question a while ago see the link below.  The vb code populates the record where all values are 0 with the populated record above.  The issue is now I need to check the dwelling type of the record with all 0's and populate with the record above with the same dwelling type.  I'm unsure of how to make this change.  I'm happy with the vb solution although if there is another approach I would also be interested.

https://www.experts-exchange.com/questions/28083252/Query-to-update-fields-with-data-from-table-rows-above.html

I've created two tables below with the original dataset and the new results I'm trying to achieve.  The dwelling types aren't grouped so the code might need to search many records above before it finds the correct dwelling type.   The  HCFMDCode is updated to B when a change is made.


The original table looks like this:

ID      DwellingType Couple      Family        Other            HCFMDCode
1           House            0.433          0.567           0                    A
2            House            0.223          0.388           0.388             A
3           House            0                  0                  0                    A
4           House            0                  0                  0                    A
5            Unit                0.355          0.332           0.332             A
6            Unit                0                  0                  0                    A

The final results should produce:
ID      DwellingType Couple      Family        Other            HCFMDCode
1           House            0.433          0.567           0                    A
2            House            0.223          0.388           0.388             A
3           House            0.223          0.388           0.388             B
4           House            0.223          0.388           0.388             B
5            Unit                0.355          0.332           0.332             B
6            Unit               0.355          0.332           0.332              B

Thanks
Comment
Watch Question
Infotrakker Software
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 8 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE