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 |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-05-17 : 11:58:16
|
| Can I use table alias anywhere in the same store procedure?For example, the code below is working?select o.id, product from order o...another code...update oset o.product = 'book'where o.id = 123 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-17 : 12:00:20
|
nope you cant. it has scope only in query you used it. so for above to work it should beselect o.id, product from order oupdate oset o.product = 'book'from order owhere o.id = 123 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-05-17 : 12:01:17
|
No you cantYou can doUPDATE o SET o.product = 'book'FROM [order] AS o Aliases are only valid for the immediate scope of the statement (or derived table etc that you alias them in).Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-05-17 : 12:05:42
|
| Thank you.As I understand, the following code is working, is it?select o.id, product from order oupdate ooset oo.product = 'book'from order oowhere oo.id = 123 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-17 : 12:09:55
|
| it will work. did you test it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2010-05-18 : 05:30:03
|
quote: Originally posted by Sun Foster Can I use table alias anywhere in the same store procedure?For example, the code below is working?select o.id, product from order o...another code...update oset o.product = 'book'where o.id = 123
look at SYNONYMS in BOL______________________ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-05-18 : 10:44:52
|
quote: Originally posted by ms65g
quote: Originally posted by Sun Foster Can I use table alias anywhere in the same store procedure?For example, the code below is working?select o.id, product from order o...another code...update oset o.product = 'book'where o.id = 123
look at SYNONYMS in BOL______________________
Actually, don't you mean ALIASES? |
 |
|
|
|
|
|
|
|