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)
1 Comment. Leave new
I used this to find the last business day
ALTER FUNCTION [dbo].[LastBusinessDay]
(
@st date
)
RETURNS date
AS
BEGIN
DECLARE @results DATE
;with LB as (
Select
dateadd(
day,
case
when datepart(weekday,@st) in(1,2)
then ~datepart(weekday,@st)
else -1
end
,@st) dd,0 t
union all
Select
dateadd(
day,
case
when datepart(weekday,lb.dd ) in(1,2)
then ~datepart(weekday,lb.dd )
else -1
end
,lb.dd ),h.hId
from LB
join dbo.Holidays h on h.HolidayDate=LB.dd
)
Select @results = min(dd) from LB
RETURN @results
END