Solved

Access Query Fill Empty Cells

Posted on 2009-05-08
8
874 Views
Last Modified: 2012-05-06
In Table A, I want to update this table so that if Column B is empty, I will replace the value for that row with the value in Column A. If Columnb B is not empty, then the value in Column B will remain.


Example 1:

Row 1      Column A = "Dog"        Colmn B = " " (empty cell)
then this is updated to:
Row 1      Column A = "Dog"        Column B = "Dog"

Example 2;

Row 2     column A  = "Dog"         Column B = "Cat"
then this row will remain as it is since B was initially filled.

I prefer a non-SQL solution (i.w. how would I arrange this in the Query Design window using criterias and expressions.

Thanks.

0
Comment
Question by:tahirih
  • 5
  • 2
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24337245
how about this

update mytable
set colb = cola
where isnull(colb) = true
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24337262
given your example, what is actually in colb, is it totally empty? or is there a space or something? to handle empty strings or space in it

update mytable
set colb = cola
where trim$(nz(colb,"")) = ""

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 450 total points
ID: 24337284
note, with the isnull, you can do this also

update mytable
set colb = cola
where colb is null
0
 

Assisted Solution

by:greyhuman
greyhuman earned 50 total points
ID: 24337288
Simple USE

IF ISNULL(B) Then B=A
ELSE B=B
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:tahirih
ID: 24337313
Please offer how I can create Table C table from Table A, and leave Table A unchanged, but the new Table C will have the udpates. The following did not work:

UPDATE A INTO C SET Div = Dept
WHERE trim$(nz(Div,""))="";

Thanks.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24337344
You cannot do a update when creating new, it will have to be a insert

this is an example of a make table query, it will create tablec for you

select cola, nz(colb,cola)
into tablec
from tablea


to use existng table

insert into tablec (cola, colb) select cola, nz(colb, cola) from tablea


the above statements copies all rows including those where colb is not null but it will contain cola value in it if null

0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 450 total points
ID: 24337347
if u just want the records with nulls in it, just extend the select so you add in where colb is null
0
 

Author Closing Comment

by:tahirih
ID: 31579500
Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now