0% found this document useful (0 votes)
115 views3 pages

Formula For Calculated Fields

The document contains contact information for Sanchit Aggarwal and details about an SQL query he created. Sanchit provides his phone number, Skype ID, and email address. He then explains that he created SQL select statements for Oracle and MS SQL to retrieve the latest transaction data for accounts based on formulas for calculated fields, including account balance calculations. Screenshots of the Oracle and MS SQL queries are included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views3 pages

Formula For Calculated Fields

The document contains contact information for Sanchit Aggarwal and details about an SQL query he created. Sanchit provides his phone number, Skype ID, and email address. He then explains that he created SQL select statements for Oracle and MS SQL to retrieve the latest transaction data for accounts based on formulas for calculated fields, including account balance calculations. Screenshots of the Oracle and MS SQL queries are included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

+91-8283837464

Skype ID - Sanchit.aggarwal84
Gmail: [email protected]

I have created SQL query (Select Statement) as per your business requirement.
Please refer the screenshots below:
1. Firstly I created the dummy tables as per the excel sheet you sent to me.
Ac This table contains account number and name.
Acbal This table contains account number, year, period and changed
data columns. Basically, Dr and Cr balances information.

2. As per the business requirement of latest change of data for an account


and based on following formulas for calculated field, I created the query.
Please see the screenshot.
Formula for Calculated Fields:
Konto: The AcNo column from the Ac Table
Beskrivelse: The Nm column from the Ac Table
Bevegelse: Calculated field: DbCh CrCh
UB: Calculated field: (DbIb CrIb) + (DbCh CrCh)

+91-8283837464

Skype ID - Sanchit.aggarwal84
Gmail: [email protected]

SQL Query (Oracle):


Select Konto,Beskrivelse,(dbch - crch) Bevelelse, ((dblb crlb) + (dbch crch))
UB
From
(select ac.acno Konto, ac.nm Beskrivelse,acbal.dbch dbch,acbal.crch
crch,acbal.dblb dblb,acbal.crlb crlb from ac,acbal where ac.acno=acbal.acno and
(acbal.acno,acbal.pr,acbal.yr)
IN
(select acno,to_number(to_char(dt,'MM')),to_number(to_char(dt,'YYYY'))
From
(select acno,max(to_date('01-'||pr||'-'||yr,'DD-MM-YYYY')) dt from acbal where
to_date('01-'||pr||'-'||yr,'DD-MM-YYYY') < sysdate group by acno
)
)
)Order by Konto;

MS SQL Query:
select konto, Beskrivelse,(dbch-crch) bevelelse,((dblb-crlb)+(dbch-crch))UB
from(Select Ac.AcNo konto,Ac.Nm Beskrivelse,AcBal.DbCh dbch,AcBal.CrCh
crch,AcBal.Dblb dblb,AcBal.Crlb crlb from Ac,acbal where Ac.AcNo=AcBal.AcNo
and Convert(varchar(50),AcBal.AcNo)+Convert(varchar(50),AcBal.Pr)
+CONVERT(varchar(50),AcBal.Yr) in
(
select Convert(varchar(4),AcNo)+Convert(varchar(2),MONTH(dt))
+Convert(varchar(4),YEAR(dt))
from
(
select AcNo,MAX(dt) dt
from
(
select AcNo,Convert(Date,Convert(varchar(4),Yr)+'-'+Convert(varchar(2),PR)+'01') dt
from AcBal where Convert(varchar(4),Yr)+'-'+Convert(varchar(2),PR)+'-01'<=
GETDATE()
)a group by AcNo

+91-8283837464
)b))c

Skype ID - Sanchit.aggarwal84
Gmail: [email protected]

You might also like