开发者

SQL code update table

开发者 https://www.devze.com 2023-04-12 04:20 出处:网络
I have two ta开发者_JAVA技巧bles: Master TableAssets 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:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消