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


Simple Interview Question


Simple Interview Question

Author
Message
sarwaanmca
sarwaanmca
SSC Rookie
SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)SSC Rookie (46 reputation)

Group: General Forum Members
Points: 46 Visits: 193
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
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28004 Visits: 39924
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Voide
Voide
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 280
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.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25886 Visits: 17512
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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Eugene Elutin
Eugene Elutin
SSCarpal Tunnel
SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)SSCarpal Tunnel (5K reputation)

Group: General Forum Members
Points: 4962 Visits: 5478
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.

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25886 Visits: 17512
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. :-P

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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3091 Visits: 24057
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/61537




Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3091 Visits: 24057
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/61537




Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25886 Visits: 17512
Mark-101232 (7/24/2013)
Here's a query using '&'

http://www.sqlservercentral.com/Forums/FindPost1422007.aspx


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.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27153 Visits: 13268
sarwaanmca (7/24/2013)
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


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 :-D


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
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