I have strings in my database that represents days in the week like this:
1234567 (all days of the week)
1230567 (all days but Thursday, EU standard - day 1 is Monday)
0000067 (no day apart from Saturday and Sunday)
And I need to write an SQL question that checks for overlaps. For instance:
1234500 and 0000067 are NOT overlapping.
while 1234500 and 0030000 are overlapping (the 3).
and 1234500 and 0000567 IS overlapping (the 5).
Each entry has an ID, customer number, and this weekday representation.
I was thinking something like this:
SELECT
*
FROM dbo.Customers c
JOIN dbo.Customers c2 ON c.CustomerNumber = c2.CustomerNumber
AND c.Days <> c2.Days
WHERE 1 = 1
AND ...?
To get two entries that are the same customer but when I come to the WHERE statement I hit a blank. Finding a substring (for instance 3) in both Days fields is very easy, but when any one of the 7 entries can be overlapping and I have to exclude 0 (not active day) then I get confused.
I need some help.
&(bitwise AND) integers to detect overlaps. (2) Fudge the strings from digits to XML and ... . (The binary approach might not be so bad if a persistent computed column was kept with the integer value of the week's bitmap.)