1

I am trying to Update a column in my table Inputcounts called concatenate off of a query called InputConcatenates that has a column also called concatenate. I am running an update query with the field name as concatenate the table name as InputCounts and the update to field as [InputConcatenates].[Concatenate]. But every time I run the query it pulls back that 0 records will be updated. Is my syntax wrong possibly?

Update Query SQL:

UPDATE InputCounts INNER JOIN InputConcatenate
ON InputCounts.CONCATENATE = InputConcatenate.CONCATENATE 
SET InputCounts.CONCATENATE = [InputConcatenate].[CONCATENATE];

InputConcatenate Query SQL:

SELECT InputCounts.FLEET, InputCounts.AMMs, [FLEET] & [AMMs] AS CONCATENATE
FROM InputCounts;
11
  • 1
    When you test this as a new query in the Access query designer, how many rows does it return? SELECT * FROM InputCounts INNER JOIN InputConcatenate ON InputCounts.CONCATENATE = InputConcatenate.CONCATENATE Commented Jan 28, 2016 at 18:55
  • 1
    Good! Now in each of those rows, the value in the InputCounts.CONCATENATE column matches the value in the InputConcatenate.CONCATENATE column of that row. Correct? Commented Jan 28, 2016 at 19:03
  • 1
    Excellent! Now what is the point of SET InputCounts.CONCATENATE = [InputConcatenate].[CONCATENATE]? (You just confirmed those values are already equal.) In the question you asked about a syntax error; the problem is a logic error. Make sense? Commented Jan 28, 2016 at 19:07
  • 1
    Still not sure I understand, but is this what you want? UPDATE InputCounts SET CONCATENATE = [FLEET] & [AMMs] WHERE CONCATENATE Is Null; Commented Jan 28, 2016 at 19:14
  • 1
    Yeah it looks like it does. If it updates the concatenate column in the table when there is no concatenate then it works fine Commented Jan 28, 2016 at 19:19

1 Answer 1

1

You reported this query accomplishes what you want ...

UPDATE InputCounts
SET CONCATENATE = [FLEET] & [AMMs]
WHERE CONCATENATE Is Null;

That may be fine. However CONCATENATE is not updated until you execute the UPDATE, and does not get updated (after having previously received a value) in response to changes in FLEET or AMMs

Decide whether CONCATENATE really needs to exist as a field in your table. You could use a query to derive it whenever you need it:

SELECT *, FLEET] & [AMMs] AS CONCATENATE
FROM InputCounts;

With the query, CONCATENATE will always be up to date.

If your database is ACCDB format and your Access version is >= 2010, another possibility is to make CONCATENATE a "calculated field" type in the table's design:

table Design View showing calculated field type

If you prefer CONCATENATE be Null whenever FLEET or AMMs is Null, change the field's Expression property to [FLEET] + [AMMs]

The advantage of a calculated field is that Access automagically updates its value without further effort (like executing an UPDATE) from you.

A disadvantage is that you can't index a calculated field. That means it's not suited for joins, WHERE criteria, ORDER BY, etc. You'll have to decide whether it's a reasonable fit for your application. :-)

Sign up to request clarification or add additional context in comments.

4 Comments

OH my gosh thats so much better I kept trying to do that but with the equal sign in front and it kept saying no ma'am lol but when you mean it cant index does that mean I cant use it as a primary key?
Right ... a primary key is implemented as a unique index ... no index possible on calculated field ... so calulated field can not be a primary key. But perhaps you could use a composite primary key based on FLEET and AMMs
How do I make a composite primary key?
Open table in Design View. Click in the box on the left of FLEET to select that field. Shift-click next to AMMs ... so you should have both those field selected. Click Primary Key icon on the ribbon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.