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


PRINT vagaries


PRINT vagaries

Author
Message
Christian Buettner-167247
Christian Buettner-167247
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5373 Visits: 3889
Hi Openminded,
I am not sure what your question is. But here is a transformation of the selects you gave which might be helpful to you.
Just remember that the unary plus (+) or minus (-) have a higher precedence than multiplication or division, which in turn also have a higher precedence than addition or substration.
Finally the calculation is executed from left to right (if not overridden by the precedence of operators or parentheses):
select 1 - 2

This is a simple substraction

select 1 + 1 * 2

This translates to 1 + (1 * 2)

select 1 +-+ 1 * 2

This translates to (1 + ((-(+1)) * 2))

select 1 +0+ 1 * 2

This translates to ((1 + 0) + (1 * 2))

select 1 ++ 1 * 2

This translates to (1 + ((+1) * 2))

Best Regards,

Chris Büttner
Open Minded
Open Minded
Mr or Mrs. 500
Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)Mr or Mrs. 500 (502 reputation)

Group: General Forum Members
Points: 502 Visits: 567
@christian That was perfect. Thanks.
krishnaroopa
krishnaroopa
SSC Veteran
SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)SSC Veteran (257 reputation)

Group: General Forum Members
Points: 257 Visits: 183
Thanks.. Now I understand.

I was wondering what happened to '-'

Also, why not it work like this:

'-' being string,
other two can implicitly convert to string?
Christian Buettner-167247
Christian Buettner-167247
SSCertifiable
SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)SSCertifiable (5.4K reputation)

Group: General Forum Members
Points: 5373 Visits: 3889
You are welcome, Open Minded

Best Regards,

Chris Büttner
Hugo Kornelis
Hugo Kornelis
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19193 Visits: 12426
krishnaroopa (7/1/2010)
Also, why not it work like this:

'-' being string,
other two can implicitly convert to string?

They can, but they won't. SQL Server uses well-defined rules for data type precedence for implicit conversions. Lower predence data types will always convert to higher precedence data types; never the other way around.
These rules are documented in Books Online. Use the index to find "data types [SQL Server]], precedence". Or read through the discussion, I believe I posted a link to this subject in the online version of BOL on one of the first pages.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)SSC Guru (68K reputation)

Group: General Forum Members
Points: 68769 Visits: 18570
Nice question - thx



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

The Dixie Flatline
The Dixie Flatline
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13354 Visits: 6903
edited: never mind

__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26501 Visits: 12506
Definitely a fun question - and interesting discussion. But, as Christian pointed out, "Print vagaries" is not the right title for this.

Tom

Tom Thomson
Tom Thomson
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26501 Visits: 12506
Hugo Kornelis (7/2/2010)
These rules are documented in Books Online. Use the index to find "data types [SQL Server]], precedence". Or read through the discussion, I believe I posted a link to this subject in the online version of BOL on one of the first pages.

No, the link is in one of Christian's posts (the 8th post in this topic) but not in either of your posts in the first 30 in this topic (where it would have been redundant after Christian's post).

Tom

Suresh.Utham
Suresh.Utham
Mr or Mrs. 500
Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)

Group: General Forum Members
Points: 552 Visits: 216
interesting question!

Suresh
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