Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL update
Message
 
 
À
04/02/2009 04:37:02
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01379140
Message ID:
01379148
Vues:
22
Update Table_Inv Set QTY = QTY + TABLE_DETAILS.Qty from Table_Inv INNER JOIN Table_Details ON Table_Inv.Code = Table_Details.Code

>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
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform