Must be an updateable query error in MS Access - sql

So I believe the below query would work in any other database except for Access. I get the 'Must be an updateable query' error. How should I rework this? (Typically I would put an INNER JOIN in the UPDATE part of the query, but I don't think I can in this instance).
UPDATE MASTER_DATA
SET VS_ID = (SELECT VS_ID FROM MASTER_VS_AND_BUILDING WHERE VALUE_STREAM = 'TERMINAL')
WHERE MATERIAL_NUMBER = 'Z12345678'

Maybe DLookup():
UPDATE MASTER_DATA
SET VS_ID = DLookup("VS_ID", "MASTER_VS_AND_BUILDING", "VALUE_STREAM = 'TERMINAL'")
WHERE MATERIAL_NUMBER = 'Z12345678'

Related

Oracle Update using a join in the select statement

I am attempting to update a field based upon data in a joined table. I've read that the Update command will not work with a table joins in the where clause. However, I cannot use the Exists command workaround as my condition is not the existence of a linked record, but rather a value in that linked record.
update stock S
set stm_auto_key=186086
From
STOCK Left Join
STOCK_RESERVATIONS On STOCK.STR_AUTO_KEY = STOCK_RESERVATIONS.STR_AUTO_KEY
Where
S.QTY_OH > 0 And
S.STM_LOT = 128729 And
STOCK_RESERVATIONS.IND_AUTO_KEY Is Null
The select statement works fine stand alone. However using it in an update command yields "SQL command not properly ended."
Thanks in advance...
I guess, you need something like this, because there might be no FROM clause in UPDATE statement:
update stock S
set stm_auto_key=186086
Where
S.QTY_OH > 0 And
S.STM_LOT = 128729 And
(SELECT STOCK_RESERVATIONS.IND_AUTO_KEY FROM STOCK_RESERVATIONS
WHERE S.STR_AUTO_KEY = STOCK_RESERVATIONS.STR_AUTO_KEY) Is Null

SQL/Excel/VBA - UPDATE query: 'Syntax Error (missing operator) in query expression'

I have very simple query that is not working and I get error:
'Syntax Error (missing operator) in query expression Tabela2.SALES2
FROM Tabela2'
Here is the code:
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela2
WHERE Tabela1.ID = Tabela2.ID
I want to run this query from VBA/Excel on Acces database (2007). Others queries with e.g. SELECT are working fine, so the problem is only with the query. And I really don't know why it is not working.
An UPDATE query using FROM is possible in SQL Server, but not in MS Access. Use this instead:
UPDATE Tabela1 INNER JOIN Tabela2 ON Tabela1.ID = Tabela2.ID
SET Tabela1.Sales = [Tabela2].[Sales2];
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela1,Tabela2
WHERE Tabela1.ID = Tabela2.ID
try this
UPDATE Tabela1
SET Tabela1.SALES = Tabela2.SALES2
FROM Tabela1
INNER JOIN Tabela2
WHERE Tabela1.ID = Tabela2.ID
Update TABLE2, TABLE1
SET TABLE2.SALES2 = TABLE1.SALES
WHERE TABLE2.ID=TABLE1.ID
hey friends try this 100% working. As per poonam FROM statement is not possible and its true but no need to inner join and make your query slow down.
This SQL Query will run on MS Access only.

Updating Field Based on Another Table

As someone new to SQL can you please point me in the right direction. I know the following is wrong but I am not sure why.
UPDATE cus
SET cus.leg_no = new.leg_no
WHERE cus.c_no = new.c_no
The cus table currently has null in the leg_no. I want to update it from the new table. I will be joining on c_no which is in both tables.
I have tried searching the web but I am getting further confused. This has lead me to think I need FROM but something is telling me that is when using SELECT rather than UPDATE.
UPDATE cus,new
SET cus.leg_no = new.leg_no
WHERE cus.c_no = new.c_no
Here's the standard way to do it:
UPDATE cus
SET cus.leg_no = (select new.leg_no from new WHERE cus.c_no = new.c_no)
Here's the SQL Server/MS access dialect way to do it:
UPDATE cus
SET cus.leg_no = new.leg_no
FROM cus
INNER JOIN new
ON cus.c_no = new.c_no
Note that, with the standard method, if there are multiple rows in new that match a particular row from cus, you'll get an error message. Whereas with the SQL Server/MS access dialect form, the system will arbitrarily select one of the rows, and issue no warning or error.

SQL Server 2008: update date from row in same column

I've seen this question a lot, but I can't seem to get my SQL to work so I'm hoping someone can help.
I've confirmed that this code will work in Access, but it isn't working with SQL Server 2008.
UPDATE shop_orders AS t1, shop_orders AS t2
SET t1.shipstreet1 = t2.shipstreet1,
t1.shipstreet2 = t2.shipstreet2,
t1.shipcity = t2.shipcity,
t1.shipregionstate = t2.shipregionstate
WHERE t1.orderid=3292
AND t2.orderid=3641;
Advice?
In SQL Server's T-SQL, you cannot have multiple tables in the UPDATE clause, nor can you give that table a table alias.
You need to use:
UPDATE shop_orders
FROM shop_orders AS t2
SET shipstreet1 = t2.shipstreet1,
shipstreet2 = t2.shipstreet2,
shipcity = t2.shipcity,
shipregionstate = t2.shipregionstate
WHERE shop_orders.orderid = 3292
AND t2.orderid = 3641;
The syntax for Update From is different for SQL server, the same query will not work in both.
See:
SQL update from one Table to another based on a ID match
For more information on Update From syntax.

Multiple Query Writing in Single Query

I have two tables in Database , I need to select a field from one table and update it in another table with a condition where id is same .. Is it Possible to write in single query ???
This should work for you:
update storage
set storage.email = (select register.email
from register
where register.id = storage.id)
Yeah it is, you could do this for example:
UPDATE Origin SET DesiredColumn = NewValue
FROM Origin
JOIN NewTable ON Origin.Id = NewTable.Id
And guess the column names were like DesiredColumn in the updating table and NewValue in the table that holds the new value.
Yes, this is possible, although the syntax depends on the type of SQL you are using.
Here is an example for T-SQL (for Microsoft SQL Server)
UPDATE
S
SET
Email = R.Email
FROM
dbo.Register R
INNER JOIN dbo.Storage S
ON S.RegisterID = R.RegisterID