Im trying to case a column to use the sum of M_DR + M_CR as the CLS_BAL. E,g if the ID is 192000801 then it should have the sum of M_DR and M_CR of ID 1920008      as its CLS_BAL as I have made in bold below.

Attach is a sample of the data I am working with.

SHEET              CAT              H_ID      ID                      CHRT_ID              OPN_BAL            M_DR                    M_CR             CLS_BAL
BALANCE      ASSETS      10122      1920008              1920008              0.00                            3000.00      0.00                     0.00
BALANCE      ASSETS      10125      192000801      192000801      0.00                      0.00                            0.00                    3000.00
BALANCE      ASSETS      10117      1930002              1930002              20847369.45            0.00                            403436.43     21250805.88
BALANCE      ASSETS      10125      193000201      193000201      0.00                            0.00                            0.00                     0.00
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
you want  M_DR + M_CR as the CLS_BA .. rite ?

try this

Select SHEET,      CAT,      H_ID,      ID,      CHRT_ID,      OPN_BAL,      M_DR,      M_CR, (M_DR + M_CR) as       n_CLS_BAL

from tablename
barkomeAuthor Commented:
Yes, but I want  ID 192000801       to have (M_DR + M_CR) of ID 1920008              
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
This relies on having only one matching row for each (shortened) ID:
from tbl a
left join (select ID, M_DR + M_CR as n_CLS_BAL from tbl) b
on left(a.ID, 7) = b.ID

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

barkomeAuthor Commented:
I was looking forward for something similar to this(syntax not correct though):

            WHEN CHRT_ID ='193000201'      THEN  (RP_M_DR + RP_M_CR WHERE CHRT_ID ='1930002')
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
You would have to use a subselect in THEN. But honestly, that does not make sense - to have fixed IDs you need to enumerate ..
            WHEN CHRT_ID ='193000201'      THEN  (select RP_M_DR + RP_M_CR from tbl WHERE CHRT_ID ='1930002')

Open in new window

It is also ineffective if used often.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
barkomeAuthor Commented:
Thanks Qlemo, I had this in mind, but had difficulty referencing 'tbl' because it my tbl is a derived table from a subquery.

The ID's I also want to have fixed are just 3 in number, and wont change.
Dale FyeOwner, Developing Solutions LLCCommented:
To avoid line wrap, embed your data inside the Code brackets, it will be far easier to read:

SHEET        CAT         H_ID       ID            CHRT_ID          OPN_BAL        M_DR          M_CR          CLS_BAL
BALANCE      ASSETS      10122      1920008       1920008             0.00       3000.00         0.00            0.00
BALANCE      ASSETS      10125      192000801     192000801           0.00          0.00         0.00         3000.00
BALANCE      ASSETS      10117      1930002       1930002      20847369.45          0.00    403436.43     21250805.88
BALANCE      ASSETS      10125      193000201     193000201           0.00          0.00         0.00            0.00

Open in new window

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
If you generate your subquery data as in my first example, or with a CTE, you should have no difficulties to access the results as in my second example.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.