|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
Tom.Thomson (3/27/2011) One comment though: depending on settings of ARITHABORT and ANSI WARNINGS, it is quite possible that none of the answer options will result, because the batch is terminated before it reaches the select statement. Why should the batch be terminated? I don't see any issues here.
Best Regards,
Chris Büttner
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
paul.james 64212 (3/28/2011) OK, can somebody suggest why this returns "Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='." on my 9.0.4207 SQL server?
declare @i tinyint SELECT @i = 0 while @i < 255 SELECT @i+=1 SELECT @i
Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='. Because this syntax is not supported in SQL Server 2005.
Best Regards,
Chris Büttner
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, August 15, 2012 9:26 AM
Points: 22,
Visits: 14
|
|
Christian Buettner-167247 (3/28/2011)
paul.james 64212 (3/28/2011) OK, can somebody suggest why this returns "Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='." on my 9.0.4207 SQL server?
declare @i tinyint SELECT @i = 0 while @i < 255 SELECT @i+=1 SELECT @i
Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='.Because this syntax is not supported in SQL Server 2005.
Ah, ok, DOH! Too much to ask for SQL server version numbers and product names to make any sense I suppose!
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 2:03 AM
Points: 3,046,
Visits: 1,307
|
|
Christian Buettner-167247 (3/28/2011)
Tom.Thomson (3/27/2011) One comment though: depending on settings of ARITHABORT and ANSI WARNINGS, it is quite possible that none of the answer options will result, because the batch is terminated before it reaches the select statement.Why should the batch be terminated? I don't see any issues here.
I've tried setting ARITHABORT and ANSI_WARNINGS on both 2005 and 2008, but the results of running the query haven't changed at all.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:12 AM
Points: 1,164,
Visits: 730
|
|
Great question. As this archaic institute I work for only has SQL2000 servers I couldn't run it even if I wanted to.
So, had to do quite a bit of digging around, and as searching for "+=" on google isn't very easy I had to be more determined than usual.
Was worth it though, learnt something knew, got it right, and (hopefully) this year we'll go to SQL 2008R2... we're planning to anyway.
_____________________________________________________________________ "The difficult tasks we do immediately, the impossible takes a little longer"
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 2:20 AM
Points: 115,
Visits: 20
|
|
I have SQL 2008, but got the Incorrect Syntax near '=' error. Btw, I have both 2005 and 2008 on my PC.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 2:03 AM
Points: 3,046,
Visits: 1,307
|
|
Donny-1012435 (3/28/2011) I have SQL 2008, but got the Incorrect Syntax near '=' error. Btw, I have both 2005 and 2008 on my PC.
Perhaps your database is in 2005 compatibility mode? Or you're running the query against the 2005 server?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Thursday, May 09, 2013 2:20 AM
Points: 115,
Visits: 20
|
|
Yes, that's correct. Connected to a known SQL2008 server and it works. Thx!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, February 06, 2013 11:51 PM
Points: 1,263,
Visits: 1,079
|
|
paul.james 64212 (3/28/2011)
Christian Buettner-167247 (3/28/2011)
paul.james 64212 (3/28/2011) OK, can somebody suggest why this returns "Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='." on my 9.0.4207 SQL server?
declare @i tinyint SELECT @i = 0 while @i < 255 SELECT @i+=1 SELECT @i
Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '='.Because this syntax is not supported in SQL Server 2005. Ah, ok, DOH! Too much to ask for SQL server version numbers and product names to make any sense I suppose!
SQL Server 2000 = v8.x; database mode 80 (aka compatibility level) SQL Server 2005 = v9.x; database mode 90 SQL Server 2008 = v10.x; database mode 100
Thanks for the QotD--great question to settle what one learned earlier.
Regards, Michael
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 12:02 PM
Points: 5,243,
Visits: 7,055
|
|
I got it correct. I was surprised at first at the "SELECT @i+=1" syntax. I knew about the compount operators and have happily used "SET @i=1", but seeing never realised that it can equally well be used with SELECT. Thanks!
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|