THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Denis Gobo

Summer SQL Teaser #5 Update

Try to guess the output if you would run this. I tested this on SQL Server 2000/2005 and 2008 (June CTP). I get the same output on all three servers.

 

CREATE TABLE #Temp (n int)

INSERT #Temp SELECT 500

 

DECLARE @number int

SET @number = 5

 

UPDATE #Temp

SET @number = n = 10

 

--What will this return

SELECT @number, n FROM #Temp

 

DROP TABLE #Temp

 

Published Thursday, June 28, 2007 9:00 AM by Denis Gobo
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Hugo Kornelis said:

Hi Denis,

Of course you get the same output on all versions of SQL Server - this syntax, though non-ANSI and very ugly, is a documented version of the UPDATE statement, so it should work the same on all versions.

See http://msdn2.microsoft.com/en-us/library/ms177523.aspx

Best, Hugo

June 28, 2007 12:50 PM
 

Denis Gobo said:

Hugo,

Wasn't there a problem with SQL Server 2000 pre SP2 (or even SP1 don't remember the details) version with this update statement?

Denis

June 28, 2007 12:55 PM

Leave a Comment

(required) 
(required) 
Submit

About Denis Gobo

I was born in Croatia in 1970, when I was one I moved to Amsterdam (and yes Ajax is THE team in Holland) and finally in 1993 I came to the US. I have lived in New York City for a bunch of years and currently live in Princeton, New Jersey with my wife and 3 kids. I work for Dow Jones as a Database architect in the indexes department, one drawback: since our data goes back all the way to May 1896 I cannot use smalldates ;-( I have been working with SQL server since version 6.5 and compared to all the other bloggers here I am a n00b. Some of you might know me from http://sqlservercode.blogspot.com/ or even from some of the newsgroups where I go by the name Denis the SQL Menace If you are a Tek-Tips user then you might know me by the name SQLDenis, I am one of the guys answering SQL Questions in the SQL Programming forum.

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement