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 |
|
btamulis
Yak Posting Veteran
64 Posts |
Posted - 2006-02-06 : 21:19:44
|
| New to SQL - trying to teach self - in reading the postings its obvious I am in the presence of greatness, pains me to ask simple question, but here goes:Two Tables:ItemMaster (Item Number, ClassID) and ItemQtyMaster (Item Number,MethodID)Objective:Update ItemQtyMaster based upon a condition exisiting in Item Master.I want to update the Method column in ItemQtyMaster Table for each item number that has ClassId = X in ItemMaster TableI tried:IF EXISTS (select * from ITEMMASTER where ClassId = 'x')BeginUpdate set Method = 2 where ITEMMASTER.ClassId = 'x'ENDerror message - The column prefix 'ITEMMASTER' does not match with a table name or alias name used in the query.Do I need to create a join or can I modify my approach? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-06 : 21:26:24
|
Welcome to SQLTeam.You can use Update command joining ItemMaster and ItemQtyMaster.Update U set U.MethodID = 2From ItemQtyMaster U inner join ItemMaster M on U.ItemNumber = M.ItemNumberWhere M.ClassId = 'x' ----------------------------------'KH' |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-02-06 : 21:28:13
|
| update ItemQtyMasterset Method = 2 from ItemQtyMaster tjoin ITEMMASTER t2 on t.[Item Number] = t2.[Item Number]where t2.ClassId = 'x'==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
btamulis
Yak Posting Veteran
64 Posts |
Posted - 2006-02-06 : 21:49:29
|
| Thanks to both - worked like a champ! |
 |
|
|
|
|
|