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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:08:29+00:00 2026-06-13T20:08:29+00:00

I need a query on below table TABLE ClienName Bal0 Bal1 Bal2 Bal3 Bal4

  • 0

I need a query on below table

TABLE

ClienName   Bal0    Bal1    Bal2        Bal3        Bal4        Bal5        Bal6    
--------------------------------------------------------------------------------
A           600     600     NULL        NULL        NULL        NULL        NULL    
B           Null    100     NULL        NULL        NULL        NULL        NULL    
C           NULL    NULL    200          NULL       NULL        NULL        NULL        
D           NULL    NULL    NULL        NULL        NULL        130         130     
E           510     510     NULL        510         510         NULL        NULL    
F           170     170     NULL        170         170         NULL        170 
G           210     210     NULL        210         210         210         210     
H           20      20      NULL        20          NULL        NULL        NULL    

Result: I would like to see the above TABLE as below, which query can do it? please help

ClienName   Bal0    Bal1    Bal2        Bal3        Bal4        Bal5        Bal6    
--------------------------------------------------------------------------------
A           600     600     600         600         600         600         600     
B           100     100     100         100         100         100         100     
C           200     200     200         200         200         200         200     
D           130     130     130         130         130         130         130         
E           510     510     510         510         510         510         510     
F           170     170     170         170         170         170         170 
G           210     210     210         210         210         210         210     
H           20      20      20          20          20          20          20
  • 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-13T20:08:30+00:00Added an answer on June 13, 2026 at 8:08 pm

    Assuming I understand what you want from your very limited example set, just go through the table and fill it column by column.

    One pass in the forward direction:

    UPDATE theTable
    SET Bal1 = Bal0
    WHERE Bal1 IS NULL AND Bal0 IS NOT NULL;
    
    UPDATE theTable
    SET Bal2 = Bal1
    WHERE Bal2 IS NULL AND Bal1 IS NOT NULL;
    
    ...
    

    And one pass in the reverse:

    UPDATE theTable
    SET Bal5 = Bal6
    WHERE Bal5 IS NULL AND Bal6 IS NOT NULL;
    
    UPDATE theTable
    SET Bal4 = Bal5
    WHERE Bal4 IS NULL AND Bal5 IS NOT NULL;
    
    ...
    

    This also (assuming “Bal” means balance, and the number has something to do with time) handles the case of differing values in columns as time increases.


    If instead you just want the first non-null column, try the COALESCE operator:

    SELECT ClienName, COALESCE(Bal0, Bal1, Bal2, Bal3, Bal4, Bal5, Bal6) AS firstBal
    FROM theTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below table which has 2 columns.I need to write a query
I have two tables described below. What I need is a single query that
Why the two query below return duplicate member_id and not the third? I need
I had a query as below in my function. In that I need to
The below shown is my query I need to order by with these three
I need to convert a sql statement to a linq query. The code below
I need to query statistics about duplicate values in my database table. For example,
I have a website that does inserts into this table below. I need to
I have a sql server query question. I have a table like below. Giving
I need to make a rather complex query, and I need help bad. Below

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.