Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
BobRoberts
Posting Yak Master
109 Posts |
Posted - 2009-06-24 : 09:50:07
|
| I have this SQL statement, which deletes any row in tblTrans that has a column ItemId which does not match the item ID of tblItem, and which also has a tblTrans.ItemFlag which is a '1'. I'm trying to figure out how to turn it into an UPDATE statement in which, instead of deleting rows from tblTrans, it simply changes ItemFlag from '1' to '0'. Here is the statement:DELETE tblTrans from tblItem i right join tblTrans uon i.itemid = u.itemid where (i.ItemId IS NULL) AND (u.ItemFlag = '1') |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-06-24 : 09:53:49
|
| update aset a.ItemFlag = '1'from tblTrans aleft join tblItem b on a.itemid = b.itemidwhere b.itemid is null |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-24 : 09:53:59
|
UPDATE tSET t.ItemFlag = 1FROM tblTrans AS tLEFT JOIN tblItem AS i ON i.ItemID = t.ItemIDWHERE i.ItemID IS NULLAND t.ItemFlag = 0 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
BobRoberts
Posting Yak Master
109 Posts |
Posted - 2009-06-24 : 10:08:29
|
quote: Originally posted by Peso UPDATE tSET t.ItemFlag = 1FROM tblTrans AS tLEFT JOIN tblItem AS i ON i.ItemID = t.ItemIDWHERE i.ItemID IS NULLAND t.ItemFlag = 0 E 12°55'05.63"N 56°04'39.26"
What significance does the AS have? Is it necessary? Also, I'm trying to change the flag FROM 1 TO 0, but I think that is probably an oversight in your code. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-24 : 10:33:59
|
Probably.UPDATE tSET t.ItemFlag = 0FROM tblTrans AS tLEFT JOIN tblItem AS i ON i.ItemID = t.ItemIDWHERE i.ItemID IS NULL AND t.ItemFlag = 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-24 : 12:37:11
|
quote: Originally posted by BobRoberts
quote: Originally posted by Peso UPDATE tSET t.ItemFlag = 1FROM tblTrans AS tLEFT JOIN tblItem AS i ON i.ItemID = t.ItemIDWHERE i.ItemID IS NULLAND t.ItemFlag = 0 E 12°55'05.63"N 56°04'39.26"
What significance does the AS have? Is it necessary? Also, I'm trying to change the flag FROM 1 TO 0, but I think that is probably an oversight in your code.
AS is optional. You can just give alias alone also |
 |
|
|
|
|
|