Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7660595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:15+00:00 2026-05-31T13:29:15+00:00

I am using SQL Server 2008r2. Here is what I am trying to accomplish:

  • 0

I am using SQL Server 2008r2.

Here is what I am trying to accomplish:

I have a table with the design:

Flag  Text
________________________
0     'No Error'
1     'Bad Data'
2     'Bad Header'
4     'Unknown error'

My second table is designed:

ID   Flags
_______________________
500  0
501  3
502  4
504  6
550  0

The flags in the second table represent a bitwise combination of the flags in the first table (e.g. Flags = 3 is ‘Bad Data’ AND ‘Bad Header’, Flags = 6 is ‘Bad Header’ AND ‘Unknown error’).

I want a query that will produce the following:

ID   ConcatText
____________________________
500  'No Error'
501  'Bad Data, Bad Header'
502  'Unknown error'
504  'Bad Header, Unknown error'
550  'No Error'

What is the best way to achieve this without the use of user-defined functions, or user-defined stored procedures?

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:29:16+00:00Added an answer on May 31, 2026 at 1:29 pm

    This article explains exactly how to accomplish this. It puts it together step by step so that you understand what is going on, too. It basically combines the bitwise operators in SQL, and then the rest is accomplished similar to what hkf posted. Hopefully, this is helpful to you 🙂

    I believe this will translate out to be:

    SELECT a.id,
        REPLACE(REPLACE(REPLACE(
        ( 
            SELECT TEXT
            FROM FlagTable AS b 
            WHERE a.flags & b.flag <> 0 
            ORDER BY b.text FOR XML Raw
        )
        , '"/><row value="', ', '), '<row value="', ''), '"/>', '') 
        AS 'attributes'
    FROM FlagMappingTable AS a
    ORDER BY a.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; Kinda new at C# here.. I got the first row
I'm using SQL Server 2008 R2 and Microsoft Excel. I have the server set
using Visual.Web.Developer.2010.Express; using SQL.Server.Management.Studio.2008.R2; What I'm ultimately trying to do is update a sql
I am using SQL Server 2008 R2, I am trying to create a dataset
OK, I am using SQL Server 2008 R2 and have a couple of relations
I'm trying to delete a couple of rows USING SQL Server management studio, for
I am using SQL Server 2008 R2 I am trying to write a single
I am using SQL Server 2008 R2 and I have an INT column where
Using SSRS 2008R2 with a SQL Server 2005 database for the Data Source. I
I have a bulk insert that works on SQL Server 2000 that I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.