## Simple Interview Question

 Author Message sarwaanmca SSC Rookie 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 & RegardsSaravanan.D Lowell One Orange Chip Group: General Forum Members Points: 28004 Visits: 39924 its a binary AND operation.` 5 = 0000010117 = 00010001`the only column in BOTH values binary representation above is the first column, representing 2^0, so the value is 1.`16 = 0001000017 = 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 SSC Rookie Group: General Forum Members Points: 38 Visits: 280 Lowell (7/24/2013)its a binary AND operation.` 5 = 0000010117 = 00010001`the only column in BOTH values binary representation above is the first column, representing 2^0, so the value is 1.`16 = 0001000017 = 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 One Orange Chip 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 SSCarpal Tunnel 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.aspxI 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 One Orange Chip 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.aspxI 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. :-PIf 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 Hall of Fame Group: General Forum Members Points: 3091 Visits: 24057 You can use '&' for decoding @@OPTIONS`PRINT @@OPTIONSIF ( (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 beforeHow to get the best help on a forumhttp://www.sqlservercentral.com/articles/Best+Practices/61537 Mark Cowne Hall of Fame 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 beforeHow to get the best help on a forumhttp://www.sqlservercentral.com/articles/Best+Practices/61537 Sean Lange One Orange Chip Group: General Forum Members Points: 25886 Visits: 17512 Mark-101232 (7/24/2013)Here's a query using '&'http://www.sqlservercentral.com/Forums/FindPost1422007.aspxI 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 One Orange Chip 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 & RegardsSaravanan.DMy 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