Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL update
Message
From
04/02/2009 04:37:02
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
SQL update
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01379140
Message ID:
01379140
Views:
71
Hi,

I have here 2 table structures and sample data with each table. I wanted to update the Qty Field in Table_Inv by adding the Qty Field in Table_Details.

Here is my UPDATE statement but it's not working.
UPDATE 
    TABLE_INV
SET
    QTY = QTY + <THE QTY IN TABLE_DETAILS>
WHERE
    WH_CODE IN (SELECT WH_CODE FROM TABLE_DETAILS)
    AND ITEM_CODE IN (SELECT ITEM_CODE FROM TABLE_DETAILS)
Table Name: Table_Inv
ID		int
WH_Code		varchar(10)
Item_Code	varchar(10)
Qty		int


Table Name: Table_Details
WH_Code		varchar(10)
Item_Code 	varchar(10)
Qty		qty



Table_Inv
ID	WH_Code		Item_Code	Qty
1	WH01		001		10
2	WH01		002		20
3	WH02		002		5
4	WH02		003		6
5	WH03		001		15

Table_Details
WH_Code	Item_Code	Qty
WH01	001		1
WH01	002		2
WH03	001		5


Expected Result
Table_Inv
ID	WH_Code		Item_Code	Qty
1	WH01		001		11
2	WH01		002		22
3	WH02		002		5
4	WH02		003		6
5	WH03		001		20
Any help would be appreciated.

Thanks
Next
Reply
Map
View

Click here to load this message in the networking platform