OK, I have a little app that I developed in ASP/SQL2K (web based, sql2K back-end). Moved to a new server with SQL2K5 and need to make a modification to one of the SQL statements. Right now I have this
And it works fine, but... I now have a secondary table that contains registration_id and additional payment info (like further payments, not more detailed info). The existing statement goes thru the registration system tables, collects the data and shows the user what has been registered for, what has been charged, what has been paid and what is owed. Now, I need to add onto that the corresponding records from another table that really just has registration id, payment and payment date. I was thinking this looks like a good place to use CTEs and all that good stuff, but as I have not used them before, I am at a bit of a loss as to where to start. Is this enough info for some help, or do you want to see the complete table structures and some sample data?
Thank you,
Willie
Code:
select rd.event_id,rd.insert_date, rd.num_spaces, cost_per_space, deposit_per_space, Total_Cost, amt_paid, (total_cost-amt_paid) AS balance_due, r.registration_id, e.ministry_id, r.contact_id
from ycmhome.contactinfo ci join ycmhome.registration r on ci.contact_id = r.contact_id
join ycmhome.reg_details rd on r.registration_id = rd.registration_id
join ycmhome.events e on rd.event_id = e.event_id
where ci.church_id = cid
and rd.event_id = eid
and r.isactive = 1
order by rd.event_id
compute sum(rd.num_spaces), sum(total_cost), sum(amt_paid), sum(total_cost-amt_paid) by rd.event_id
And it works fine, but... I now have a secondary table that contains registration_id and additional payment info (like further payments, not more detailed info). The existing statement goes thru the registration system tables, collects the data and shows the user what has been registered for, what has been charged, what has been paid and what is owed. Now, I need to add onto that the corresponding records from another table that really just has registration id, payment and payment date. I was thinking this looks like a good place to use CTEs and all that good stuff, but as I have not used them before, I am at a bit of a loss as to where to start. Is this enough info for some help, or do you want to see the complete table structures and some sample data?
Thank you,
Willie