T Sql join query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ish27
    New Member
    • Apr 2012
    • 1

    T Sql join query

    i have a problems in joins. if i run two queries separately it runs fine but if run using joins its creating problem

    Code:
    SELECT 
    Div, Bill,  count(CPT)) as [Count(Paid Claims)],sum(ChgAmt)as [Charges Paid($)],sum(PayAmt)as [Payments($)], SUM(PayAmt) / SUM(ChgAmt) as [PMT/CHG(%)] ,sum(PayAmt)/ convert(int,count(CPT)) as [AVG PMT ($)] FROM dbo.PaymentFile group by   Bill, Div order by  Div asc, Bill asc
    and second query is

    Code:
    SELECT  
    Div, Bill,count(CPT) as [Count(Claims)],sum(ChgAmt)as [Charges($)]
    FROM dbo.TransactionFile group by   Bill, Div order by  Div asc, Bill asc
    and if i join this query like this

    Code:
    SELECT  
    t.Div, t.Bill, (t.CPT)) as [Count(Claims)], sum(t.ChgAmt)as [Charges($)],
    p.Div, p.Bill, (p.CPT))as [Count(Paid Claims)],sum(p.ChgAmt)as [Charges Paid($)],
    sum(p.PayAmt)as [Payments($)],(p.CPT))/(t.CPT)) as [Claims(Paid %)],
    sum(p.PayAmt)/sum(p.ChgAmt)as [PMT/CHG(%)],
    sum(p.PayAmt)/count(p.CPT) as [AVG PMT ($)]
    FROM dbo.TransactionFileas t,dbo.PaymentFile as p
    group by   t.Bill, t.Div,  p.Bill, p.Div
    order by  t.Div asc, t.Bill asc

    its taking more than an hour to execute and

    i was also getting error in conversion failed when converting the varchar value to data type int

    bcoz cpt column is varchar but when i run separately no error occurs

    please help me out

    thanks in advance
    Last edited by PsychoCoder; Apr 16 '12, 06:12 AM. Reason: Code tags added
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Check your JOIN syntax....

    Happy Coding!!!


    ~~ CK

    Comment

    Working...