Earlier I posted a puzzle SQL Puzzle – SELECT ~ 1 : Guess the Answer, which got over 123 answers. Lots of people said they were not able to believe this puzzle happening in the real world and based on the request, I have made the recent video on the same topic of the bitwise puzzle.
Let me know what you think of this puzzle and solution. A little bit more about Bitwise operators: Bitwise operators perform bit manipulations between two expressions of any of the data types of the integer data type category. Bitwise operators convert two integer values to binary bits, perform the AND, OR, or NOT operation on each bit, producing a result. Then converts the result to an integer.
Let me know if you are interested to know more about this topic like a bitwise puzzle and I will write more blogs as well as create an SQL in Sixty Seconds video.
Here are my few recent videos and I would like to know what is your feedback about them.
- Find Expensive Queries – SQL in Sixty Seconds #159
- Case-Sensitive Search – SQL in Sixty Seconds #158
- Wait Stats for Performance – SQL in Sixty Seconds #157
- Multiple Backup Copies Stripped – SQL in Sixty Seconds #156
Reference: Pinal Dave (http://blog.SQLAuthority.com)
I used this to find the last business day
ALTER FUNCTION [dbo].[LastBusinessDay]
DECLARE @results DATE
;with LB as (
when datepart(weekday,@st) in(1,2)
,@st) dd,0 t
when datepart(weekday,lb.dd ) in(1,2)
then ~datepart(weekday,lb.dd )
join dbo.Holidays h on h.HolidayDate=LB.dd
Select @results = min(dd) from LB