Solved

Dynamicallyfilled column in select statement based on one of three fields

Posted on 2011-09-13
2
285 Views
Last Modified: 2012-06-21
I have a query that is almost exactly what I need, however I need to add a Column to the end where I have the dummy field of active account to display the account the has '_Sys' from which ever of the OACT (T1, T2, or T3) AcctCode fields that matches that criteria.

Any help would be greatly appreciated.

* Only 1 of the fields will ever contain the '_Sys' code.

Best of luck,
John-Michael
(Select T0.AcctCode, T0.AcctName, T0.Levels, T0.GrpLine, T0.FatherNum, T0.GroupMask, 
T1.AcctCode, T1.GroupMask, 
T2.AcctCode, T2.GroupMask,
T3.AcctCode, T3.GroupMask, T3.FormatCode,
'Active Account' as 'Active Account'

from OACT T0 
Left Outer Join OACT T1 on T1.FatherNum = T0.AcctCode
Left Outer Join OACT T2 on T2.FatherNum = T1.AcctCode
Left Outer Join OACT T3 on T3.FatherNum = T2.AcctCode
Where T0.Levels = 1)



Order By T0.GroupMask

Open in new window

0
Comment
Question by:John-Michael_Davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 250 total points
ID: 36533193
use case
(Select T0.AcctCode, T0.AcctName, T0.Levels, T0.GrpLine, T0.FatherNum, T0.GroupMask, 
T1.AcctCode, T1.GroupMask, 
T2.AcctCode, T2.GroupMask,
T3.AcctCode, T3.GroupMask, T3.FormatCode,
case 
  when T1.AcctCode = '_SYS' then
    T1.AcctCode
  when T2.AcctCode = '_SYS' then
    T2.AcctCode  
  when T3.AcctCode = '_SYS' then
    T3.AcctCode  
  else
    ''
 end [Active Account]

from OACT T0 
Left Outer Join OACT T1 on T1.FatherNum = T0.AcctCode
Left Outer Join OACT T2 on T2.FatherNum = T1.AcctCode
Left Outer Join OACT T3 on T3.FatherNum = T2.AcctCode
Where T0.Levels = 1)



Order By T0.GroupMask

Open in new window

0
 
LVL 1

Author Closing Comment

by:John-Michael_Davis
ID: 36533271
Excellent solution, worked like a charm.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question