SQL Query

Discussion in 'Software' started by jcast, May 18, 2012.

  1. jcast

    jcast Private E-2

    Hi;

    I have this query:

    select
    f.sClientReference AS 'G&M Ref',
    f.FileNumber AS 'JSM File',
    o.sFirstName + ' ' + o.sLastOrganizationName AS 'Debtor',

    CASE when (t.TransType = 'CC')
    then SUM(t.TransAmount)
    ELSE 0 END AS 'Total cost Spent',

    CASE when (t.TransType = 'DP')
    then SUM(t.TransAmount)
    ELSE 0 END AS 'Total Collected',

    CASE when l.dtFinalJudgmentDate is not null
    then l.cFinalJudgmentAmount
    ELSE a.cPrincipalClaimAmount END AS 'Total Principal Awarded',

    CASE when l.dtFinalJudgmentDate is not null
    then l.cFJInterest
    ELSE a.cReferralInterest END AS 'Total Interest Awarded',

    CASE when l.dtFinalJudgmentDate is not null
    then l.cFJFees
    ELSE l.cStipulationFees END AS 'Attorney Fees'
    from tblFile AS f
    inner join tblOpponent AS o on f.FileNumber = o.dFileNumber
    inner join Transact AS t on f.FileNumber = t.FileNumber
    inner join tblLitigat AS l on f.FileNumber = l.dFileNumber
    inner join tblAccount AS a on f.FileNumber = a.lFileNumber
    where f.ClientCode like 'NEWM%' and o.dOpponentNumber = 1
    and (f.StatusCode = 'NEWF' or f.StatusCode = 'OPEN' or
    f.StatusCode = 'REOP') and (t.TransType = 'CC' or t.TransType = 'DP')
    group by f.FileNumber, f.sClientReference, t.TransType,
    o.sFirstName, o.sLastOrganizationName, l.dtFinalJudgmentDate,
    l.cFinalJudgmentAmount, a.cPrincipalClaimAmount,
    l.cFJInterest, a.cReferralInterest, l.cFJFees,
    l.cStipulationFees, t.transType
    order by f.FileNumber

    I am getting the results I want but I am getting 2 rows per file number becasue of the transType = CC and transtype = DP..
    one row return the total of transtype = CC and the other row the transtype = DP and I need everything in one row. I dont know how to mix these two cases. This is what I am getting:

    G&M File # Debtor Total CC Total DP Principal Interest AF
    01-95463 132673 Meir Leib -563.50 0.00 3000.00 NULL 0
    01-95463 132673 Meir Leib 0.00 66.14 3000.00 NULL 0


    But what I really want is the combination of these 2 rows
    01-95463 132673 Meir Leib -563.50 66.14 3000.00 NULL 0

    Please help me.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds