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

Simple Interview Question Expand / Collapse
Author
Message
Posted Wednesday, July 24, 2013 7:29 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, March 15, 2014 10:37 AM
Points: 46, Visits: 182
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
Post #1477050
Posted Wednesday, July 24, 2013 7:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 7:44 AM
Points: 12,910, Visits: 32,015
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1477057
Posted Wednesday, July 24, 2013 8:26 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, June 17, 2014 10:17 AM
Points: 31, Visits: 278
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.
Post #1477090
Posted Wednesday, July 24, 2013 8:38 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 13,302, Visits: 12,168
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 Moden's 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)
Post #1477100
Posted Wednesday, July 24, 2013 8:50 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 7:27 AM
Points: 2,836, Visits: 5,067
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1477110
Posted Wednesday, July 24, 2013 9:03 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 13,302, Visits: 12,168
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 Moden's 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)
Post #1477117
Posted Wednesday, July 24, 2013 9:13 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 6:13 AM
Points: 1,694, Visits: 19,550
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'



____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1477125
Posted Wednesday, July 24, 2013 9:34 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, April 8, 2014 6:13 AM
Points: 1,694, Visits: 19,550
Here's a query using '&'

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


____________________________________________________

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537

Never approach a goat from the front, a horse from the rear, or a fool from any direction.
Post #1477135
Posted Wednesday, July 24, 2013 9:42 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:32 PM
Points: 13,302, Visits: 12,168
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 Moden's 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)
Post #1477138
Posted Thursday, July 25, 2013 1:47 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:26 AM
Points: 13,622, Visits: 10,514
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




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

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1477370
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse