We help IT Professionals succeed at work.
Get Started

SQL Query Help - find Field Name within Text - Iterative loop

Last Modified: 2015-10-03

I need some help to write an SQL query please.  I have a problem in my application where using calculated fields works fine when working with database fields or constants, and is also fine when a calculated field is used within another calculated field.  It break when there are nested calculated fields beyond 1 level deep.  I wish to construct a SQL query to identify to me any records which this affects.

Here is a sample of some rows where the problem exists:

TableID	FieldName	Seq	DataType	IsCalculated	Formula	FieldFormat	FieldLabel	Alias
Calculated	HrlyCost	8	decimal	1	50			
Calculated	VarOnWag	14	decimal	1	(ProcLabCost + PackLabCost) * 999	->>,>>9.99	Variable on Wages	Calculated_VarOnWag
Calculated	FixOnBas	18	decimal	1	BaseCost * 999	->>,>>9.99	Fixed on Base	Calculated_FixOnBas
Calculated	FullCost	19	decimal	1	WageCost + VarOnWag + BaseCost + FixOnBas	->>,>>9.99	Fully Costed	Calculated_FullCost
Calculated	PackLabCost	12	decimal	1	(HrlyCost * Part_UD.Number07) / NULLIF((Part_UD.Number06 * 999), 0)	->>,>>9.99	Packing Labour Cost	Calculated_PackLabCost
Calculated	BaseCost	17	decimal	1	CostPart.StdMaterialCost * 150 / NULLIF(100, 0)	->>,>>9.99	Base Cost incl Waste	Calculated_BaseCost
Calculated	ProcLabCost	11	decimal	1	Part1_UD.Number05 * Part.NetWeight	->>,>>9.99	Process Labour Cost	Calculated_ProcLabCost
Calculated	WageCost	13	decimal	1	ProcLabCost + PackLabCost	->>,>>9.99	Wages Cost	Calculated_WageCost
Calculated	PPK	22	decimal	1	FullCost / NULLIF(Part.NetWeight, 0)	->>,>>9.99	Cost PPK	Calculated_PPK

Open in new window

I'll also try to demonstrate the nested fields here:

The field PPK as you can see above has 4 levels.  

Is there anyway to query for and show the number of levels based on the data provided above?

Many Thanks
Watch Question
ERP System Manager
This problem has been solved!
Unlock 2 Answers and 7 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE