<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Return weekday from a stored int value with sql in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824105#M4854948</link>
    <description>&lt;P&gt;You are right, the answer in both my examples is false. I wrote wrong there. 
Ok, this is probably what I'm looking for. How do I write this in a sql in a condition?&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2020 15:42:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2020-10-07T15:42:37Z</dc:date>
    <item>
      <title>Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaq-p/13824101</link>
      <description>&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;CREATE TABLE WeekDay (DeliveryWeekdays INTEGER NOT NULL);

INSERT INTO WeekDay(DeliveryWeekdays) values (7);
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;We have a program that stores an int value in a table with which weekdays you have selected in a check box.&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;{
    None = 0,
    Monday = 1,
    Tuesday = 2,
    Wednesday = 4,
    Thursday = 8,
    Friday = 16,
    Saturday = 32,
    Sunday = 64,
}
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;&lt;IMG alt="alt text" src="https://i.stack.imgur.com/Dbeh2.png" /&gt;&lt;/P&gt;
&lt;P&gt;Ex: If you have checked Monday and Thursday the value is 9 in the field in the table. If you checked Monday, Tuesday, Wednesday the value is 7 in the field and so on..&lt;/P&gt;
&lt;P&gt;The question is whether with a date I can check if the day of the week in that date is in the int value stored in the table.&lt;/P&gt;
&lt;P&gt;If I check the date 2020-10-08, I see that it is a Thursday. I want to check if Thursday is in value 7. The answer is yes. If the int value is 3, the answer will be no.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 12:13:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaq-p/13824101</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-10-07T12:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824104#M4854947</link>
      <description>&lt;P&gt;I'm not sure I understand your requirements (and is the second/third last statements true?) - but when you want to compare a value against set bits in an integer, SQL Anywhere offers bitwise operators here, see &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/816a58d36ce21014ab45d3d19f97565b.html"&gt;Bitwise operators&lt;/A&gt;. So to check against the "Thursday" flag, you could test with &amp;lt;myvalue&amp;gt; &amp;amp; 0x0008 != 0, and for "Friday" with &amp;lt;myvalue&amp;gt; &amp;amp; 0x0010 != 0.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:32:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824104#M4854947</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-10-07T15:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824105#M4854948</link>
      <description>&lt;P&gt;You are right, the answer in both my examples is false. I wrote wrong there. 
Ok, this is probably what I'm looking for. How do I write this in a sql in a condition?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:42:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824105#M4854948</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-10-07T15:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824106#M4854949</link>
      <description>&lt;P&gt;It's difficult to show some code if we don't know how you access the test date (the possible delivery date, I assume) and the according "possible delivery week days" (per customer, I further assume). So it would be helpful to show some sample table entries...&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:49:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824106#M4854949</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-10-07T15:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824107#M4854950</link>
      <description>&lt;P&gt;Yes, that's right. I thought of overall examples of how I can use this in practice.
How, based on a date, can I convert Friday (5) to 0x0010 etc.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 15:53:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824107#M4854950</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-10-07T15:53:41Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824102#M4854945</link>
      <description>&lt;P&gt;Is this what you're looking for:&lt;/P&gt;
&lt;P&gt;select dow(current date) weekday, POWER(2,weekday-2) theday,
(if (theday &amp;amp; 0x12) = 0 then 1 else 0 endif) &lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 07:29:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824102#M4854945</guid>
      <dc:creator>fvestjens</dc:creator>
      <dc:date>2020-10-08T07:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824103#M4854946</link>
      <description>&lt;P&gt;Here's a sample based on Frank's approach (corrected for Sunday) - in real use cases, you would provide the test date and the "allowed weekday flags" via table data, I assume:&lt;/P&gt;
&lt;PRE&gt;-- use with clause to calculate the number of days for the current month
-- via subtracting one day from the next month's first day
-- Note: This is just used to build a list of all days of the current month,
-- so just for testing purposes
with cd as (select current date as cur_date,
            day(dateadd(dd, -1, ymd(year(cur_date), month(cur_date) + 1, 1))) as current_month_day_count)

-- list every day of this month and its weekday value and turn that into an according flag
-- and compare this with a given "allowed_days_flag" (here for Monday, Tuesday and Friday)
select ymd(year(cd.cur_date), month(cd.cur_date), current_month.row_num) as test_date,
   dow(test_date) weekday,
   dayname(test_date) dayname,
   power(2, if weekday = 1 then 6 else weekday - 2 end if) dayofweek_flag,
   0x01 | 0x02 | 0x10 as allowed_days_flags,
   if dayofweek_flag &amp;amp; allowed_days_flags = dayofweek_flag then 1 else 0 endif as fitting
from cd cross apply dbo.sa_rowgenerator(1, cd.current_month_day_count) current_month
order by 1;
&lt;/PRE&gt;

&lt;P&gt;This will return the folowing list:&lt;/P&gt;
&lt;PRE&gt;test_date   weekday dayname dayofweek_flag  allowed_days_flags  fitting
2020-10-01  5   Thursday    8   0x13    0
2020-10-02  6   Friday  16  0x13    1
2020-10-03  7   Saturday    32  0x13    0
2020-10-04  1   Sunday  64  0x13    0
2020-10-05  2   Monday  1   0x13    1
2020-10-06  3   Tuesday 2   0x13    1
2020-10-07  4   Wednesday   4   0x13    0
2020-10-08  5   Thursday    8   0x13    0
2020-10-09  6   Friday  16  0x13    1
2020-10-10  7   Saturday    32  0x13    0
2020-10-11  1   Sunday  64  0x13    0
2020-10-12  2   Monday  1   0x13    1
2020-10-13  3   Tuesday 2   0x13    1
2020-10-14  4   Wednesday   4   0x13    0
2020-10-15  5   Thursday    8   0x13    0
2020-10-16  6   Friday  16  0x13    1
2020-10-17  7   Saturday    32  0x13    0
2020-10-18  1   Sunday  64  0x13    0
2020-10-19  2   Monday  1   0x13    1
2020-10-20  3   Tuesday 2   0x13    1
2020-10-21  4   Wednesday   4   0x13    0
2020-10-22  5   Thursday    8   0x13    0
2020-10-23  6   Friday  16  0x13    1
2020-10-24  7   Saturday    32  0x13    0
2020-10-25  1   Sunday  64  0x13    0
2020-10-26  2   Monday  1   0x13    1
2020-10-27  3   Tuesday 2   0x13    1
2020-10-28  4   Wednesday   4   0x13    0
2020-10-29  5   Thursday    8   0x13    0
2020-10-30  6   Friday  16  0x13    1
2020-10-31  7   Saturday    32  0x13    0&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Oct 2020 03:53:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824103#M4854946</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-10-09T03:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824108#M4854951</link>
      <description>&lt;P&gt;One question, how do I get the dow to work if Monday is the first day of the week?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 16:07:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824108#M4854951</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-10-11T16:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824109#M4854952</link>
      <description>&lt;P&gt;It should not matter here because DOW is not dependent on the "first_day_of_week" option, to &lt;A href="http://dcx.sap.com/index.html#sqla170/en/html/81f6e6d96ce21014a676894207f98640.html"&gt;quote&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;The DOW function is not affected by the value specified for the first_day_of_week database option. For example, even if first_day_of_week is set to Monday, the DOW function returns a 2 for Monday.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want to additionally "list" the week day according to your current locale  (and you have set the "first_day_of_week" option to 1 or whatever), you can still add the according value via "select ..., datepart(dw, test_date), ..." to the query above, as dateapart(dw) does reflect that option. But the calculation itself is easier via DOW because, as stated, it's not dependent on that option.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 04:45:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824109#M4854952</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-10-12T04:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824110#M4854953</link>
      <description>&lt;P&gt;Ok, thanks.&lt;/P&gt;
&lt;P&gt;A quick question. Your example is very good but I'm probably too stupid to understand it how works.&lt;/P&gt;
&lt;P&gt;If I retrieve value 7 from a field in my select, how can I use the Power function to check if the day of the week in datepart (cdw, today ()) is in 7?
I know that value 7 in this case contains Monday = 1, Tuesday = 2,
and Wednesday = 4 so it should return 1. If I run this select tomorrow, my value will be 0.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 14:12:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824110#M4854953</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-10-14T14:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Return weekday from a stored int value with sql</title>
      <link>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824111#M4854954</link>
      <description>&lt;P&gt;Well, as stated originally:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;It's difficult to show some code if we don't know how you access the test date (the possible delivery date, I assume) and the according "possible delivery week days" (per customer, I further assume). So it would be helpful to show some sample table entries...&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have decided not to do so, so I guess I can't give further help .&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 07:38:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/return-weekday-from-a-stored-int-value-with-sql/qaa-p/13824111#M4854954</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2020-10-15T07:38:45Z</dc:date>
    </item>
  </channel>
</rss>

