looking up into another table base on a filter
asembereng
Member Posts: 220
I have two tables to collect data from while running a report. The report is design on the History table and it needs to get data also from the loan_history table based on two fields it should compare; the empid and the MonthYear. But when running the report. How can i get data from the loan_history table when both the empid and the MonthYear is the same?
for example
select loan_history.monthly_deductions from loan_history, History where history.empid = loan_history.empid and history.MonthYear= loan_history.MonthYear;
If it was in mysql..
thanks
for example
select loan_history.monthly_deductions from loan_history, History where history.empid = loan_history.empid and history.MonthYear= loan_history.MonthYear;
If it was in mysql..
thanks
0
Comments
-
select loan_history.monthly_deductions from loan_history, History where history.empid = loan_history.empid and history.MonthYear= loan_history.MonthYear;
IF history.FINDSET THEN REPEAT loan_history.SETRANGE(empid, history.empid); loan_history.SETRANGE(MonthYear, history.MonthYear); IF loan_history.FINDSET THEN //Do your thing UNTIL history.NEXT = 0
Does that get you started?0 -
thank you very much.. now i want to loop into this table if base on empid and the monthYear if it exit it should display and error or else execute the following
history.RESET; IF history.FINDLAST THEN LintHistory_ID := history.id; loan.RESET; //loan.SETCURRENTKEY("Freeze Loan",balance); loan.SETRANGE("Freeze Loan",FALSE); loan.SETFILTER(balance,'>0'); IF loan.FINDSET(TRUE,TRUE) THEN // TRUE,TRUE because you want to change the table REPEAT loan2 := loan; // if you change records inside a loop, you NEED a second variable in which you change the record op_bal := loan2.balance; cl_bal := loan2.balance - loan2.monthly_pay; paidoff := loan2.loan_amount - cl_bal; loan2.paidoffamount := paidoff; loan2.balance := cl_bal; loan2.MODIFY; // no need for 2 modifies of the same table //insert into loan history table. LintHistory_ID += 1; CLEAR(history); history.id := LintHistory_ID; history.op_balance := op_bal; history.cl_balance := cl_bal; history.ded_amount := loan2.monthly_pay; history.int_amount := loan2.monthly_int; history.loan_id := loan2.id; history.empid := loan2.empid; history."Run Date" := RunDate; history.MonthYear :=FORMAT(RunDate,0,'<Month text> <Year4>');; history.INSERT(FALSE); // the record doesn't exist, so you need to INSERT it and not MODIFY it UNTIL loan.NEXT = 0;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
