I am trying to run this update qry in SQL Server: UPDATE [mfgtest803].[dbo].[partplant]
SET [reschedoutdelta] = '1'
WHERE ([partplant].[partnum] = [partWhse].[partnum])AND
(([partplant].[safetyqty]>'0')OR([partplant].[minimumqty]>'0'))AND
([partWhse].[WarehouseCode]='120')
I get the following errors: Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "partWhse.partnum" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "partWhse.WarehouseCode" could not be bound.
But this select statement works fine: SELECT [partplant].[plant]
,[partplant].[partnum]
,[partplant].[primwhse]
,[partplant].[minimumqty]
,[partplant].[maximumqty]
,[partplant].[safetyqty]
,[partplant].[reschedoutdelta]
,[partplant].[reschedindelta]
,[partplant].[nonstock]
,[partWhse].[WarehouseCode]
FROM [mfgtest803].[dbo].[partplant], [mfgtest803].[dbo].[partWhse]
WHERE ([partplant].[partnum] = [partWhse].[partnum])AND
(([partplant].[safetyqty]>'0')OR([partplant].[minimumqty]>'0'))AND
([partWhse].[WarehouseCode]='120')
Can someone help me understand what is wrong and how to fix?
thanks!
This is a different problem altogether.
if a partplant record has corosponding partwhse records equal to 120 but not 320,
By this you mean UPDATE if partwhse has a corresponding value of 120 ONLY.
If this is so then (excuse me while I remove all the brackets, are you using Access?) - WHERE (partplant.safetyqty > 0
-
OR partplant.minimumqty > 0) AND
-
(partWhse.WarehouseCode = 120
-
AND COUNT(partWhse.WarehouseCode) = 1)
This is assuming your JOIN is correct.
If more than two entries are allowed (multiple 120 or other values) then a sub-query will probably be needed - WHERE ..id.. NOT IN
-
(SELECT ..id.. FROM partWhse
-
WHERE partWhse.WarehouseCode = 320)
..or similar
5 1454 code green 1,726
Recognized Expert Top Contributor
Please remove the Bold My eyes are hurting.
You haven't done a JOIN on partWhse that is why the error states 'cannot be found'
thanks CG! That was it. (sorry about the bolding)
I now have this q:
UPDATE [mfgtest803].[dbo].[partplant]
SET [reschedindelta] = '15'
FROM [mfgtest803].[dbo].[partplant] JOIN [mfgtest803].[dbo].[partWhse] ON ([partplant].[partnum]=[partWhse].[partnum])
WHERE (([partplant].[safetyqty]>'0')OR([partplant].[minimumqty]>'0'))AND
(([partWhse].[WarehouseCode]='120') AND([partWhse].[WarehouseCode]<>'320'))
But there is a problem --> a partplant record often has 2 corosponding partwhse records, whose values could be 120 and 320. IF this is the case, I do not want to update (i.e., if a partplant record has corosponding partwhse records equal to 120 but not 320, then do the update). The above query updates any partplant record that has a corosponding partwhse record = 120. Am I making sense? How can I stop this?
thanks for your help CG
code green 1,726
Recognized Expert Top Contributor
This is a different problem altogether.
if a partplant record has corosponding partwhse records equal to 120 but not 320,
By this you mean UPDATE if partwhse has a corresponding value of 120 ONLY.
If this is so then (excuse me while I remove all the brackets, are you using Access?) - WHERE (partplant.safetyqty > 0
-
OR partplant.minimumqty > 0) AND
-
(partWhse.WarehouseCode = 120
-
AND COUNT(partWhse.WarehouseCode) = 1)
This is assuming your JOIN is correct.
If more than two entries are allowed (multiple 120 or other values) then a sub-query will probably be needed - WHERE ..id.. NOT IN
-
(SELECT ..id.. FROM partWhse
-
WHERE partWhse.WarehouseCode = 320)
..or similar
got it - thanks. I will give that a try. I will need the sub-q.
Thanks for your help! this did the trick:
UPDATE [mfgtest803].[dbo].[partplant]
SET [reschedindelta] = '15'
FROM [mfgtest803].[dbo].[partplant] JOIN [mfgtest803].[dbo].[partWhse] ON ([partplant].[partnum]=[partWhse].[partnum])
WHERE (([partplant].[partnum]
NOT IN
(SELECT [partWhse].[partnum] FROM [mfgtest803].[dbo].[partWhse] WHERE [partWhse].[WarehouseCode]<>'120'))
AND
(([partplant].[safetyqty]>'0')OR([partplant].[minimumqty]>'0')))
BTW, I am running this via SQL Management Studio Express - it does not run without the brackets...
Thanks Again!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
I have 2 tables, one with names, and another with addresses, joined by their
CIVICID number (unique to the ADDRESSINFO table) in Oracle.
I need to update a field in the NAMEINFO table for a...
|
by: Lauren Quantrell |
last post by:
In VBA, I constructed the following to update all records in
tblmyTable with each records in tblmyTableTEMP having the same
UniqueID:
UPDATE
tblMyTable RIGHT JOIN tblMyTableTEMP ON...
|
by: bolidev |
last post by:
I'm new to SQL and can't figure out how to update my table
(StoreItemStatus) that contains the current status for items in each
store (STORE_KEY, ITEM_KEY, STATUS,...).
I get updated status info...
|
by: kalamos |
last post by:
This statement fails
update ded_temp a
set a.balance = (select sum(b.ln_amt)
from ded_temp b
where a.cust_no = b.cust_no
and a.ded_type_cd = b.ded_type_cd
and a.chk_no = b.chk_no
group by...
|
by: serge |
last post by:
/*
This is a long post. You can paste the whole message
in the SQL Query Analyzer.
I have a scenario where there are records
with values pointing to wrong records and I need to fix them
using an...
|
by: 001 |
last post by:
Hello,
The select statement needs only 1 second to complete the query.
But the update statement spends 30 minutes. Why?
SELECT STATEMENT:
declare @IDate smalldatetime
select @IDate=col001...
|
by: Harry Broomhall |
last post by:
I wonder if anybody could give me a few pointers on a problem I face.
I need to do an UPDATE on table A, from an effective left outer join
on A and another table B. (This is trying to perform a...
|
by: Jeff Kowalczyk |
last post by:
I need to adapt this an update statement to a general
form that will iterate over multiple orderids for a given
customerinvoiceid. My first concern is a form that will
work for a given orderid,...
|
by: Sim Zacks |
last post by:
The following query updated all the rows in the
AssembliesBatch table, not just where batchID=5.
There are 2 rows in the AssembliesBatch table with batch ID of
5 and I wanted to update both of...
|
by: Mark Dexter |
last post by:
In Microsoft SQL Server, I can write an UPDATE query as follows:
update orders set RequiredDate =
(case when c.City IN ('Seattle','Portland') then o.OrderDate + 2 else
o.OrderDate + 1 end)...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |