Solved

Dynamicallyfilled column in select statement based on one of three fields

Posted on 2011-09-13
2
282 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
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Index and Stats Management-Specific tables 8 38
How can I get the entire database script? 7 24
error doing substr 3 33
Checking for column changes SQL 2014 4 16
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

713 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