Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««1234»»»

Operators Expand / Collapse
Author
Message
Posted Monday, March 28, 2011 2:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 7:19 AM
Points: 2,814, Visits: 3,851
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
Post #1084774
Posted Monday, March 28, 2011 2:56 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 7:19 AM
Points: 2,814, Visits: 3,851
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
Post #1084777
Posted Monday, March 28, 2011 3:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 15, 2012 9:26 AM
Points: 23, 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!
Post #1084779
Posted Monday, March 28, 2011 3:24 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, April 03, 2014 10:34 AM
Points: 3,352, Visits: 1,478
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.
Post #1084789
Posted Monday, March 28, 2011 3:29 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, August 27, 2013 4:28 AM
Points: 1,248, Visits: 779
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"
Post #1084791
Posted Monday, March 28, 2011 3:31 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 2:57 AM
Points: 129, Visits: 23
I have SQL 2008, but got the Incorrect Syntax near '=' error.
Btw, I have both 2005 and 2008 on my PC.
Post #1084792
Posted Monday, March 28, 2011 3:51 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, April 03, 2014 10:34 AM
Points: 3,352, Visits: 1,478
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?
Post #1084801
Posted Monday, March 28, 2011 3:58 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 2:57 AM
Points: 129, Visits: 23
Yes, that's correct. Connected to a known SQL2008 server and it works. Thx!
Post #1084802
Posted Monday, March 28, 2011 3:58 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 09, 2013 11:12 PM
Points: 1,263, Visits: 1,081
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
Post #1084803
Posted Monday, March 28, 2011 4:45 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:32 PM
Points: 5,794, Visits: 8,006
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
Post #1084825
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse