Bitwise T-SQL Sample



CREATE TABLE Tree_Contacts  (Nodename varchar(10), options int)
INSERT Tree_Contacts  values('Node1', 1)
 ,('Node2', 2)
 ,('Node3', 3)
,('Node4', 7)
,('Node4', 6)

Select a.Nodename
    , Replace( Replace( Replace(( 
        Select col 
        From ( VALUES (1,'Access to Client'),(2,'Access to ADMIN'),(4,'Access to web')) AS b(options, col)
        Where a.options & b.options <> 0 
        Order By b.col For XML Raw)
        , '"/><row col="', ', '), '<row col="', ''), '"/>', '') 
        As 'ApplicationAccesstest'
From Tree_Contacts  a
Order By a.Nodename;

Drop table Tree_Contacts 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s