SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Update Set clause using aliased table incorrect column list

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Update Set clause using aliased table incorrect column list
Author Message
judahr



Joined: 09 Mar 2007
Posts: 319
Country: United States

Post Update Set clause using aliased table incorrect column list Reply with quote
5.1.10 Pro
SSMS 2008
SQL 2000

Code:
Update t
Set
From dbo.Table2 t2
    Inner join dbo.Table1 t
       On t2.ID = t.ID

Pulling up the column list on the set clause uses the columns from Table2 instead of Table1. If Table1 was the first table, it works properly.

(I may be reporting this one again. If so, sorry.)
Wed Sep 22, 2010 9:13 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7907

Post Reply with quote
This doesn't work as you expect. The behavior for T-SQL specific syntax for UPDATE alias SET... FROM table list/joins is the same as for SELECT ... FROM table list/joins. "FROM" clause is driving the column prompt, not the UPDATE. That's why the columns are listed in the order or table references. We have a queued enhancement in the pipeline to implement recognition and handling of T-SQL specific UPDATE … FROM statements.
Wed Sep 22, 2010 10:11 am View user's profile Send private message
judahr



Joined: 09 Mar 2007
Posts: 319
Country: United States

Post Reply with quote
One related item. If you have an update where the table you are updating is the first table specified and the table is aliased:

Code:
Update t
Set
From dbo.Table1 t
    Inner join dbo.Table2 t2
       On t1.ID = t2.ID


each of the columns on the left side of the assignement in the set clause is aliased:
Code:
Set t.Field1 = t2.Field1

It should be
Code:
Set Field1 = t2.Field1



Another item, in the preceding example, if you select t2.Field1, it ends up:
Code:
Set Field1 = t2.Field1 = ?


should be
Code:
Set Field1 = t2.Field1

Wed Sep 29, 2010 11:33 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7907

Post Reply with quote
Thank you for your suggestions.

All of that does require indeed an SQL intellisene method specific to UPDATE...FROM syntax. I'm going to copy your suggestions to the queue enhacment.
Wed Sep 29, 2010 9:55 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.