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 123»»»

T-SQL SQL 2008 Expand / Collapse
Author
Message
Posted Saturday, June 19, 2010 9:21 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 9:21 AM
Points: 5,099, Visits: 20,191
Comments posted to this topic are about the item T-SQL SQL 2008

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #940014
Posted Sunday, June 20, 2010 11:42 PM


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: 2 days ago @ 1:49 AM
Points: 3,123, Visits: 4,310
Good question.
These operators are often overlooked and are definately underused.


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #940098
Posted Sunday, June 20, 2010 11:53 PM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Friday, May 10, 2013 3:15 AM
Points: 1,476, Visits: 1,943
Personally i would rather see them not being used. You dont really gain anything by using them. Only makes the code harder to read. Saving a few keypresses vs loosing readability is in my mind a bad trade.

Well i would think that you wont gain any performance on it anyway. SQL still have to do the math. But havent been able to test... no SQL2008
Post #940099
Posted Monday, June 21, 2010 12:19 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 12:55 AM
Points: 1,101, Visits: 1,191
+= or *= are quite easy, but |= or even ^= wanted a little thinking on bitwise arithmetics.
Nice equestion.




See, understand, learn, try, use efficient
© Dr.Plch
Post #940105
Posted Monday, June 21, 2010 12:40 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: 2 days ago @ 1:32 AM
Points: 3,187, Visits: 4,140
stewartc-708166 (6/20/2010)
These operators ... are definately underused.

Maybe because they are not compatible with SQL Server 2005 and below?
Post #940110
Posted Monday, June 21, 2010 12:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 4:24 AM
Points: 5,232, Visits: 7,022
Good question, but the explanation is lacking. I think that the +=, -=, etc operators are generally even better known than the bitwise operators used here (even if they were done in SQL-2005 compatible format such as SET @b = @b & 1).

The explanation that should have been there is:
& - bitwise AND. Convert operators to binary, do a bit-by-bit AND operation (result bit is 1 if both input bits are 1), then convert the result back to the result data type. In the example here, 5 AND 1 becomes:
5 = 0101
1 = 0001
---- &
0001 = 1


| - bitwise OR. Convert operators to binary, do a bit-by-bit OR operation (result bit is 1 if either input bit is 1), then convert the result back to the result data type. In the example here, 5 OR 1 becomes:
5 = 0101
1 = 0001
---- |
0101 = 5


^ - bitwise exclusive OR. Convert operators to binary, do a bit-by-bit exclusive OR operation (result bit is 1 if exactly one bit is 1), then convert the result back to the result data type. In the example here, 5 OR 1 becomes:
5 = 0101
1 = 0001
---- ^
0100 = 4


% - modulo. I assume the readers here to be familiar with this operator.

(EDIT - attempt to edit formatting of leading spaces)



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #940114
Posted Monday, June 21, 2010 2:46 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 4:56 AM
Points: 1,256, Visits: 4,253
Picture didn't appear on the e-mail--had to come here before it showed up. That happen to anyone else?
Post #940163
Posted Monday, June 21, 2010 2:55 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354, Visits: 1,299
I had to guess because I didn't know the ^= operator but I knew all the others. I was lucky that the other three were specific enough that I guessed correctly.

So why doesn't the Explanation discuss the ^= operator? What is that?
Post #940173
Posted Monday, June 21, 2010 3:00 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 9:52 AM
Points: 1,356, Visits: 4,761
I agree with Hugo - I knew the modulus answer, but had no idea what the others were. So got it correct as only one option had the right value for @e :)
Post #940177
Posted Monday, June 21, 2010 5:03 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:51 AM
Points: 21,357, Visits: 9,531
Toreador (6/21/2010)
I agree with Hugo - I knew the modulus answer, but had no idea what the others were. So got it correct as only one option had the right value for @e :)


Same here, I was instantly 100% sure about the % and low and behold, I didn't have to think any further .
Post #940235
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse