SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Operators


Operators

Author
Message
Christian Buettner-167247
Christian Buettner-167247
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3625 Visits: 3889
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
Christian Buettner-167247
Christian Buettner-167247
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3625 Visits: 3889
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
paul.james 64212
paul.james 64212
SSC Rookie
SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)SSC Rookie (29 reputation)

Group: General Forum Members
Points: 29 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!
Duncan Pryde
Duncan Pryde
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3602 Visits: 1552
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.
DugyC
DugyC
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1430 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"
Donny-1012435
Donny-1012435
SSC-Enthusiastic
SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)

Group: General Forum Members
Points: 135 Visits: 31
I have SQL 2008, but got the Incorrect Syntax near '=' error.
Btw, I have both 2005 and 2008 on my PC.
Duncan Pryde
Duncan Pryde
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3602 Visits: 1552
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?
Donny-1012435
Donny-1012435
SSC-Enthusiastic
SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)SSC-Enthusiastic (135 reputation)

Group: General Forum Members
Points: 135 Visits: 31
Yes, that's correct. Connected to a known SQL2008 server and it works. Thx!:-D
michael.kaufmann
michael.kaufmann
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1339 Visits: 1082
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
Hugo Kornelis
Hugo Kornelis
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11182 Visits: 12004
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search