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 8048751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:34:37+00:00 2026-06-05T06:34:37+00:00

Given a table of input data I would like to have a set o

  • 0

Given a table of input data I would like to have a set o “flag columns” that describe sibling columns of the same record.

  • I am using Microsoft SQL Server 2005.
  • First of all I need to load data in the target table, then I need to perform checks to put values in those flag columns.

Say for example I have a toy table like the following one:

CREATE TABLE zzz_test
             (
                          color        VARCHAR(10),
                          value_x      INTEGER    ,
                          value_y      INTEGER    ,
                          value_x_FLAG bit        ,
                          value_y_FLAG bit
             )

Then I have the following toy data (I need to repeat the INSERT/VALUES statements for every record because of the “old” 2005 SQL version):

INSERT zzz_test(color,value_x,value_y)
VALUES('red',1,NULL)
INSERT zzz_test(color,value_x,value_y)
VALUES('green',NULL,NULL)
INSERT zzz_test(color,value_x,value_y)
VALUES('red',NULL,2)
INSERT zzz_test(color,value_x,value_y)
VALUES('red',1,3)
INSERT zzz_test(color,value_x,value_y)
VALUES('black',NULL,1)
INSERT zzz_test(color,value_x,value_y)
VALUES(NULL,3,2)
INSERT zzz_test(color,value_x,value_y)
VALUES('black',1,2)
INSERT zzz_test(color,value_x,value_y)
VALUES('red',3,4)
INSERT zzz_test(color,value_x,value_y)
VALUES('green',1,1)
INSERT zzz_test(color,value_x,value_y)
VALUES('blue',5,NULL)

Now I would like to have a quick way to put values inside value_x_FLAG and value_y_FLAG evaluating if sibling columns value_x and value_y are NULL.

I know that there are functions like ISNULL(), or COALESCE(), but I do not think this is the case because I am trying to update a column given the value of another column.

I know I can use IF / ELSE statements but it’s quite complicate to set all the cases of many boolean flags (2^n) to work all together in the same “update” statement of the flag variables.

How to deal with it?

After setting all the flags I would like to summarize in some way my table. For example I would like to have a COUNT on all the flag variables, then I would like to have a COUNT given the “color category“.

Probably I do not need a set of support flag variables, but I would like to have them to make the table much more readable, and also the SQL code much more readable.
Thanks!

  • 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-06-05T06:34:38+00:00Added an answer on June 5, 2026 at 6:34 am

    try this, after all inserts, do

    update zzz_test set value_x_FLAG = CASE value_x when null then 1 else 0 END, value_y_FLAG = CASE value_y when null then 1 else 0 END
    

    hope it works!

    edit: about the count, you can use group by clause everytime you need it, instead of have a flag saved in somewhere

    select Color, Count(value_x_FLAG) from zzz_test  group by Color having value_x_FLAG != 0
    

    this will return a 2 column table, with the color and int the other column the number of rows that have the flag = 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data that looks a bit like this: Name StartTime
I have a table inside a form that looks as follows: <td><input type=text name=code[0]
I have a table that contains index data, with each row having a start
I have a huge set of data of tables in Open Office 3.0 document
I have a table with about 1000 records and 2000 columns. What I want
I have this small table of data. Dir LinkL LinkH East 19 27 East
I would like to do something like simple data binding in Windows Forms, but
There is a table T that contains data as shown below: A B ---------
I have populated an html form with MySQL data from a table. I have
Given this table structure and example data (t3 should not be used in the

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.