July 24, 2013 at 7:29 am
select 5 & 17
What is the Output?
Ans is :1
1)how it will return 1 ?
2)what is the use of this query?
any one explain it pls..
Thank & Regards
Saravanan.D
July 24, 2013 at 7:36 am
its a binary AND operation.
5 = 00000101
17 = 00010001
the only column in BOTH values binary representation above is the first column, representing 2^0, so the value is 1.
16 = 00010000
17 = 00010001
when AND-ing 16, and 16, the only shared column si the 2^4 column, which is 16.
Lowell
July 24, 2013 at 8:26 am
Lowell (7/24/2013)
its a binary AND operation.
5 = 00000101
17 = 00010001
the only column in BOTH values binary representation above is the first column, representing 2^0, so the value is 1.
16 = 00010000
17 = 00010001
when AND-ing 16, and 16, the only shared column si the 2^4 column, which is 16.
I just had PTSD flashbacks to assembly.
July 24, 2013 at 8:38 am
I would have to say that is an absolutely horrid interview question. It is not testing your skills with sql server. I have seen the binary AND around the forums but I have never come across it in the real world (at least not in sql server).
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 24, 2013 at 8:50 am
Sean Lange (7/24/2013)
I would have to say that is an absolutely horrid interview question. It is not testing your skills with sql server. I have seen the binary AND around the forums but I have never come across it in the real world (at least not in sql server).
It's called "Bitwise AND" :
http://msdn.microsoft.com/en-us/library/ms174965.aspx
I have used it few times...
I'll try to find one thread on this forum where I've used it to help to achieve quite interesting requirements.
July 24, 2013 at 9:03 am
Eugene Elutin (7/24/2013)
Sean Lange (7/24/2013)
I would have to say that is an absolutely horrid interview question. It is not testing your skills with sql server. I have seen the binary AND around the forums but I have never come across it in the real world (at least not in sql server).It's called "Bitwise AND" :
http://msdn.microsoft.com/en-us/library/ms174965.aspx
I have used it few times...
I'll try to find one thread on this forum where I've used it to help to achieve quite interesting requirements.
I knew it wasn't binary AND but couldn't think of the proper name for the life of me. 😛
If you can find that thread it would be interesting.
I still say it is a poor interview question because it so rarely used.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 24, 2013 at 9:13 am
You can use '&' for decoding @@OPTIONS
PRINT @@OPTIONS
IF ( (8 & @@OPTIONS) = 8 ) PRINT 'ANSI_WARNINGS'
IF ( (16 & @@OPTIONS) = 16 ) PRINT 'ANSI_PADDING'
IF ( (32 & @@OPTIONS) = 32 ) PRINT 'ANSI_NULLS'
IF ( (64 & @@OPTIONS) = 64 ) PRINT 'ARITHABORT'
IF ( (256 & @@OPTIONS) = 256 ) PRINT 'QUOTED_IDENTIFIER'
IF ( (512 & @@OPTIONS) = 512 ) PRINT 'NOCOUNT'
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537July 24, 2013 at 9:34 am
Here's a query using '&'
http://www.sqlservercentral.com/Forums/FindPost1422007.aspx
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537July 24, 2013 at 9:42 am
Mark-101232 (7/24/2013)
Here's a query using '&'
I remember that thread. And I would say that yes it can be done but the end result is a static set of values. I would say that doing this in sql is rather pointless.
Your example of parsing OPTIONS though is pretty cool.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 25, 2013 at 1:47 am
sarwaanmca (7/24/2013)
select 5 & 17What is the Output?
Ans is :1
1)how it will return 1 ?
2)what is the use of this query?
any one explain it pls..
Thank & Regards
Saravanan.D
My answer to a question like this (if I wouldn't know the answer):
"Can you show me a useful query for this?"
Probably will knock their socks off 😀
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
July 25, 2013 at 2:06 am
Sean Lange (7/24/2013)
Your example of parsing OPTIONS though is pretty cool.
Yes, it's useful for querying any information stored as a bitmask, such as affinity masks or the freq_interval column in sysschedules.
John
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply