?
Solved

Dynamicallyfilled column in select statement based on one of three fields

Posted on 2011-09-13
2
Medium Priority
?
286 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 1000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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...
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 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