k_cire0426
Yak Posting Veteran
63 Posts |
Posted - 2010-10-12 : 23:52:48
|
Hello..PROCEDURECREATE PROCEDURE usp_VCReportProcedure(@FromQuery as INT,@ToQuery as INT)ASSELECT * FROM (SELECT TOP 100 PERCENT ROW_NUMBER() OVER(ORDER BY (Select 0)) as RowCountID,* FROM (' & SQLQueryString & ') tblVCReport ) tblVCReport2WHERE RowCountID Between @FromQuery and @ToQuery order by RowCountIDquery SELECT TOP 100 PERCENT vyu_SMReportPreference.*, tblGL.dtmDate as dtmDate, 'Account ID: ' + isnull(tblGL.strAccountID,'') + ' Total:' as strTransactionIDFooter, isnull(tblGL.strTransactionID,'') as strTransactionID, isnull(tblGL.strBatchID,'') as strBatchID, isnull(tblGL.strAccountID,'') as strAccountID, isnull(tblGL.strAccountGroup,'') as strAccountGroup, isnull(tblGLBeginBalance.dblBeginBalance,0) AS dblBeginBal, ISNULL(CASE WHEN qsrpGLAccountSegment.strAccountType = 'Asset' OR qsrpGLAccountSegment.strAccountType = 'Expense' THEN ISNULL(tblGL.dblDebit,0) - ISNULL(tblGL.dblCredit,0) ELSE ISNULL(tblGL.dblCredit,0) - ISNULL(tblGL.dblDebit,0) END,0) AS dblTotal, isnull([dblDebit],0) - isnull([dblCredit],0) + isnull([dblDebit],0) - isnull([dblCredit],0) as dblSumBalance, CASE WHEN lower(tblGL.strReference) NOT like '%opening balance%' AND lower(tblGL.strDescription) NOT like '%opening balance%' THEN isnull(tblGL.dblDebit,0) ELSE 0 END as dblDebit, CASE WHEN lower(tblGL.strReference) NOT like '%opening balance%' AND lower(tblGL.strDescription) NOT like '%opening balance%' THEN isnull(tblGL.dblCredit,0) ELSE 0 END as dblCredit, dblOpeningBalances = CASE WHEN lower(tblGL.strReference) like '%opening balance%' OR lower(tblGL.strDescription) like '%opening balance%' THEN ISNULL(CASE WHEN qsrpGLAccountSegment.strAccountType = 'Asset' OR qsrpGLAccountSegment.strAccountType = 'Expense' THEN ISNULL(tblGL.dblDebit,0) - ISNULL(tblGL.dblCredit,0) ELSE ISNULL(tblGL.dblCredit,0) - ISNULL(tblGL.dblDebit,0) END,0) ELSE 0 END, case when tblGL.strCode = 'GJ' then case when strJournalLineDescription not LIKE '%opening balance%' then isnull(tblGL.strJournalLineDescription,'') ELSE isnull(tblGL.strDescription,'') END else isnull(tblGL.strDescription,'') end as strDescription, tblGL.strCode as strCode, tblGL.dtmDateEntered as dtmDateEntered, isnull(tblGL.strJobID,'') as strJobID, isnull(tblGL.strReference,'') as strReference, isnull(tblGL.strCode,'') as strFormDrillDownCode, 'Acct ID: ' + isnull(tblGL.strAccountID,'') + ' - ' + isnull(qsrpGLAccountSegment.strDescription,'') + ' - ' + isnull(qsrpGLAccountSegment.strAccountType,'') + ' Account' AS strCOADescription, isnull(qsrpGLAccountSegment.strAccountType,'') as strAccountType, isnull(qsrpGLAccountSegment.strDescription,'') as strAccountDescription, isnull(tblGL.strCode,'') as strGLCode, qsrpGLAccountSegment.strSEgmentCode, vyu_GLDynamicSegment.*FROM vyu_SMReportPreference, tblGL LEFT JOIN tblGLAccount as qsrpGLAccountSegment ON tblGL.strAccountID = qsrpGLAccountSegment.strAccountID left join vyu_GLDynamicSegment on vyu_GLDynamicSegment.AccountID = tblGL.strAccountID Left Join tblGLBeginBalance on tblGLBeginBalance.strAccountID = tblGL.strAccountIDWHERE tblGL.ysnIsUnposted = 0INDEXNONCLUSTERED - strAccountID,strAccountGroup,cntID,dtmDate,strBatchID,strTransactionID,strProductIDCLUSTERED - cntID |
 |
|