sql - INT to Binary and then read bits -


i have int value in database, storing selected days of week.

for example, 65 = 1000001

which mean:

1:sun 0:mon 0:tue 0:wed 0:thu 0:fri 1:sat 

so then, need land small temp table with:

dayofweek: sunday saturday 

so, read int, , output table of days.

can done in sql server?

; tbl (     select  col = 65    union     select  col = 3 ) select  *    tbl t     cross apply     (         select dayofweek = 'sun' col & 64 = 64    union         select dayofweek = 'mon' col & 32 = 32    union         select dayofweek = 'tue' col & 16 = 16    union         select dayofweek = 'wed' col &  8 =  8    union         select dayofweek = 'thu' col &  4 =  4    union         select dayofweek = 'fri' col &  2 =  2    union         select dayofweek = 'sat' col &  1 =  1     ) d 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -