views:

18

answers:

1

Suppose you're updating a table that is the result of an expression, like so

UPDATE OPENQUERY( server, 'SELECT a from b' )
   SET rem.a = loc.a
  FROM OPENQUERY( server, 'SELECT a from b' ) rem
      ,local_table loc
 WHERE rem.id = loc.id

Will that OPENQUERY be executed once, or twice? I believe the same would apply to any kind of updatable query expression.

Also, is there any way for me to alias it so that it does not need to be repeated?

+2  A: 

Just as I asked, I thought I'd try this

UPDATE rem
   SET rem.a = loc.a
  FROM OPENQUERY( server, 'SELECT a from b' ) rem
      ,local_table loc
 WHERE rem.id = loc.id

and it works!

So I'll leave it here in case it may help anyone else.

harpo
I use UPDATE/DELETE aliases quite often. I find it clearer.
gbn
I use UPDATE/DELETE aliases quite often. My aliases are shorter than table names and im lazy.
Sung Meister