SQL code update table
I have two ta开发者_JAVA技巧bles:
Master Table Assets Table
-AssetNo- -AssetNo-
AssetNo
is the PK, and it's a foreign key to link the two tables. Now, I'd like to update using:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
If I use this command, all asset with the same assetno
will automatic update to 1.
How to code with specific assetNo
IE: WHERE 111(from Assets)=111(from Master)
If I understand your question correctly, I think you just need another condition in your WHERE clause:
UPDATE Assets
SET status = 1
FROM Assets, Master
WHERE Assets.AssetNo = Master.AssetNo
AND Assets.AssetNo = 111
What sql engine are you using? Something like this would work for sql server:
Update a
SET Status = 1
FROM Assets a
JOIN Master m on a.AssetNo = m.AssetNo
WHERE a.AssetNo = 111
UPDATE Assets SET status = 1
FROM Assets a JOIN Master m ON a.AssetNo = m.AssetNo
WHERE a.AssetNo = 999
UPDATE a
SET a.Status = 1
FROM Assets AS a
INNER JOIN Master AS m ON a.AssetNo = m.AssetNo
WHERE m.AssetNo = @value
精彩评论