0% found this document useful (0 votes)
1 views

canvas_preview

The document contains a complex SQL query constructed in VB.NET that retrieves transaction data, including priority, dates, amounts, and descriptions from multiple tables. It uses various SQL functions like NVL and SUM to handle null values and aggregate data, while also applying filters based on user-defined variables. The query is structured to provide a detailed report of transactions, including opening balances and grouped results by specific criteria.

Uploaded by

Yash Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

canvas_preview

The document contains a complex SQL query constructed in VB.NET that retrieves transaction data, including priority, dates, amounts, and descriptions from multiple tables. It uses various SQL functions like NVL and SUM to handle null values and aggregate data, while also applying filters based on user-defined variables. The query is structured to provide a detailed report of transactions, including opening balances and grouped results by specific criteria.

Uploaded by

Yash Shinde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

User:

You said:

l_str_cl = " SELECT Priority," & " Nvl(To_Char(Dt, 'DD-MON-RR'), '') Dt," & "
Nvl(To_Char(Due_Date, 'DD-MON-RR'), '') Due_Date," & " Exch," & " Seg," & "
Description1," & " Bcm_Code," & " Nvl(To_Char(Voucher), '') Voucher," & "
Dr_Amt," & " Cr_Amt" & " FROM (SELECT Priority," & " Trn_Date Dt," & "
Due_Date," & " Bcm_Code," & " Trn_Dbcr," & " Exm Exch," & " Seg Seg," & "
Voucher," & " Nvl(Chq_No, '') Cheque_No," & " Nvl(Acm_Name, '')
Account_Name," & " Nvl(Narration, '') Description1," & "
To_Char(SUM(Nvl(Debit, 0)), 'FM9999999990D90') Dr_Amt," & "
To_Char(SUM(Nvl(Credit, 0)), 'FM9999999990D90') Cr_Amt" & " FROM
(SELECT 2 Priority," & " a.Trn_Bcm_Code Bcm_Code," & " a.Trn_Dbcr," & "
a.Trn_Acm_Acc_Code Acccode," & " a.Trn_Doc_Series ||'/'|| Trn_Doc_Serial_No
Voucher," & " a.Trn_Exm_Id Exm," & " a.Trn_Seg_Id Seg," & " a.Trn_Chq_No
Chq_No," & " Decode(a.Trn_Dbcr, 'D', a.Trn_Amount, 0) Debit," & "
Decode(a.Trn_Dbcr, 'C', a.Trn_Amount, 0) Credit," & " Trn_Short_Narration
Narration," & " a.Trn_Date Trn_Date," & " a.Trn_Due_Dt Due_Date," & "
Acm_Name" & " FROM Transactions a," & " Account_Master" & " WHERE

in
a.Trn_Exm_Id = Nvl('" & g_exch & "', a.Trn_Exm_Id)" & " AND a.Trn_Seg_Id =
.
f
Nvl('" & g_seg & "', a.Trn_Seg_Id)" & " AND a.Trn_Acm_Acc_Code =
d
op
Acm_Acc_Code" & " AND a.Trn_Date BETWEEN" & " To_Date('" & g_strt_dt &

t
"', 'DD-MON-RRRR') AND" & " To_Date('" & g_end_dt & "', 'DD-MON-RRRR')" &
p
" AND a.Trn_Approval_Flag = 'Y'" & " AND a.Trn_Acm_Acc_Code = " &
g
a t
g_Ledger_id & " UNION ALL" & " SELECT 1 Priority," & " MAX('-') Bcm_Code,"
& " NULL Trn_Dbcr," & " NULL," & " NULL," & " Nvl(NULL, '') Exm," & "
c h
Nvl(NULL, '') Seg," & " MAX(Cheque_No)," & "
Nvl(MAX(Decode(Sign(SUM(Debit) - SUM(Credit))," & " 1," & " (SUM(Debit) -
SUM(Credit))," & " 0))," & " 0) Debit," & " Nvl(MAX(Decode(Sign(SUM(Debit) -
SUM(Credit))," & " -1," & " (SUM(Credit) - SUM(Debit))," & " 0))," & " 0)
Credit," & " 'Opening Balance as on ' ||" & " To_Char(To_Date('" & g_strt_dt &
"', 'DD-MON-RRRR')," & " 'DD-MON-RR')," & " MAX(To_Date(NULL, 'DD-MON-
RR'))," & " MAX(To_Date(NULL, 'DD-MON-RR'))," & " Nvl(NULL, '') Acm_Name"
& " FROM (SELECT 1 Priority," & " NULL Bill_Number," & " NULL
Contract_No," & " Acccode," & " Nvl('NSE', 'ALL') Exm," & " Nvl('E', 'B') Seg,"
& " NULL Cheque_No," & " Decode(Sign(SUM(Debit) - SUM(Credit))," & " 1,"
& " (SUM(Debit) - SUM(Credit))," & " 0) Debit," & " Decode(Sign(SUM(Debit) -
SUM(Credit))," & " -1," & " (SUM(Credit) - SUM(Debit))," & " 0) Credit," & "
NULL," & " NULL," & " Nvl(NULL, '') Acm_Name" & " FROM (SELECT
Ahg_Acm_Acc_Code Acccode," & " Ahg_Exm_Id Exm," & " Ahg_Seg_Id Seg,"
& " SUM(Decode(Ahg_Opening_Balance_Dbcr," & " 'D'," & "
Ahg_Opening_Balance," & " 0)) Debit," & "
SUM(Decode(Ahg_Opening_Balance_Dbcr," & " 'C'," & "
Ahg_Opening_Balance," & " 0)) Credit," & " Acm_Name," & " NULL Chq_No"
& " FROM Account_History_General," & " Account_Master" & " WHERE
Ahg_Exm_Id = Nvl('" & g_exch & "', Ahg_Exm_Id)" & " AND Ahg_Seg_Id =
Nvl('" & g_seg & "', Ahg_Seg_Id)" & " AND Ahg_Acm_Acc_Code =
Acm_Acc_Code" & " AND NVL(Acm_Ldg_Type,'C') IN ('D', 'C')" & " AND
Acm_Grp_Acc = 'A'" & " AND Ahg_Acm_Acc_Code = " & g_Ledger_id & " AND

Generated via chatgptopdf.in | Preview only


(Ahg_Apm_Start_Period," & " Ahg_Apm_End_Period) IN" & " (SELECT
DISTINCT Apm_Start_Period," & " Apm_End_Period" & " FROM
Account_Period_Master" & " WHERE Apm_Start_Period <=" & " To_Date('" &
g_strt_dt & "'," & " 'DD-MON-RRRR')" & " AND Apm_End_Period >=" & "
To_Date('" & g_end_dt & "'," & " 'DD-MON-RRRR'))" & " GROUP BY
Ahg_Cpd_Id," & " Ahg_Exm_Id," & " Ahg_Seg_Id," & " Ahg_Acm_Acc_Code," &
" Acm_Name" & " UNION ALL" & " SELECT Trn_Acm_Acc_Code Acccode," & "
a.Trn_Exm_Id Exm," & " a.Trn_Seg_Id Seg," & " SUM(Decode(a.Trn_Dbcr," & "
'D'," & " a.Trn_Amount," & " 0)) Debit," & " SUM(Decode(a.Trn_Dbcr," & " 'C',"
& " a.Trn_Amount," & " 0)) Credit," & " Acm_Name," & " NULL Chq_No" & "
FROM Transactions a," & " Account_Master" & " WHERE a.Trn_Exm_Id =
Nvl('" & g_exch & "', a.Trn_Exm_Id)" & " AND a.Trn_Seg_Id = Nvl('" & g_seg &
"', a.Trn_Seg_Id)" & " AND a.Trn_Acm_Acc_Code = Acm_Acc_Code" & " AND
a.Trn_Approval_Flag = 'Y'" & " AND a.Trn_Date >=" & " (SELECT
Apm_Start_Period" & " FROM Account_Period_Master" & " WHERE
Apm_Start_Period <=" & " To_Date('" & g_strt_dt & "'," & " 'DD-MON-RRRR')"
& " AND Apm_End_Period >=" & " To_Date('" & g_end_dt & "'," & " 'DD-MON-
RRRR'))" & " AND a.Trn_Date <" & " To_Date('" & g_strt_dt & "', 'DD-MON-
RRRR')" & " AND a.Trn_Acm_Acc_Code = " & g_Ledger_id & " GROUP BY
Trn_Acm_Acc_Code," & " a.Trn_Cpd_Id," & " a.Trn_Exm_Id," & " a.Trn_Seg_Id,"
& " a.Trn_Subledger_Id," & " a.Trn_Chq_No," & " a.Trn_Last_Updt_Dt," & "
a.Trn_Creat_Dt," & " Acm_Name)" & " GROUP BY Acccode," & " Acm_Name)"
& " GROUP BY Priority," & " Bill_Number," & " Acccode," & " Exm," & " Seg,"

in
& " Cheque_No," & " Acm_Name" & " ORDER BY 1," & " Trn_Date)" & "
.
f
GROUP BY Priority," & " Trn_Date," & " Due_Date," & " Bcm_Code," & "
d
op
Trn_Dbcr," & " Exm," & " Seg," & " Voucher," & " Nvl(Chq_No, '')," & "
Nvl(Acm_Name, '')," & " Nvl(Narration, '')," & " 0" & " ORDER BY Priority," & "

p t
Dt)" can you explain this code line by line to me this code is based on the

t g
vb.net code which is executing the SQL in backend

h a
c

Get Full PDF (Free Signup)

Sign up to download the full PDF and unlock more features like:

Export longer conversations


🎨 Color-coded messages
🧩 Customizable or removable watermarks
🔎 HTML previews before download
🚀 Early access to new features

Generated via chatgptopdf.in | Preview only

You might also like