|  | Posted by Hugo Kornelis on 06/27/07 17:39 
On Tue, 26 Jun 2007 17:27:42 -0700, --CELKO-- wrote:
 > The illegal
 >syntax you used can do multiple updates on each row; talk to an old
 >Sybase programmer about this problem.
 
 Hi Joe,
 
 It's not illegal. It's non-standard, but in SQL Server (check the name
 of this group!!), it's legal and documented. And in many cases much
 faster than the ANSI-standard equivalent - an ommission I keep kicking
 the optimizer team for until they finallly get it right, but until that
 day we developers have to code our way around it.
 
 >UPDATE A  SET field1
 >     = (SELECT  C.field1                  FROM B, C
 >       WHERE A.guid1 = B.guid1
 >            AND B.guid2 = C.guid2             AND C.somekind_type = 1
 >          AND @my_date BETWEEN B.start_date AND B.end_date);
 
 Oh boy, I really hope that Richard runs a quick test or two (oh wait,
 one should be enough with such glaring errors) before deploying this
 "alternative" in production.
 
 I think that this snippet of code is a good contender for not only the
 worst code ever posted to usenet, but also for the worst formatting. If
 I were a book author, I'd now have to ask you for permission to include
 it as a sample of bad query writing (though the reader probably wouldn't
 believe it -hah! as if I even *could* come up with something this bad).
 
 --
 Hugo Kornelis, SQL Server MVP
 My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
  Navigation: [Reply to this message] |