I think what I want to do is fairly straightforward but the data I get back varies greatly.
select sum(cast(vi.qty - vi.unredeemed as bigint))
from red.dbo.setup vc
full join red.dbo.test bt
on bt.batch_no = vc.batch_no
join red.dbo.live vi
where vi.date_issued between '2012-01-01' and '2012-01-01'
and vc.denom ='1'
and substring(vi.issue_id,3,1) = '4'
What I am trying to do is join 3 tables together then sum of qty
of the results of the join and then minus the unredeemed so as to give a redeemed total in one row.
I have tried various amendments to my sum field but the numbers back seem huge so I think it is multiplying them.
I haven't used joins for a while and I am a bit rusty.