Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Correlated Subqueries Expand / Collapse
Posted Thursday, September 11, 2008 2:32 AM


Group: General Forum Members
Last Login: Tuesday, October 4, 2011 8:20 AM
Points: 13, Visits: 20

I have a request from one of my clients to produce a report that lists all his client information and fee details. My problem is that all the fee information is contained in the one table and I need to pass the query three different paramater values for Directors fees, Takeon fees and Fee listing.

Obviously if I use the where statement to filter my recordset I will exclude the records that don't have values for all of the parameters.

I have seen how subqueries can overcome issues like this by effectively running recursive selects on recordsets but I am not sure if this is the way to go. I have produced a couple of basic subqueries but if anyone who has more experience could guide me as to the suitability of the method or suggest a better approach I would be very grateful.

Thank you kindly,

Post #567534
Posted Thursday, September 11, 2008 5:24 AM


Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,661, Visits: 23,078
I would suggest you help us help you a bit:
Post #567630
Posted Friday, September 12, 2008 1:57 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 2, 2014 6:07 AM
Points: 227, Visits: 138
If I understood you right...could you join to the same table a multiple times to get the different information...something like this...
You would join to the Fees table on the client, but each time only join for the Fee type you are looking for.
Not the best performing query...but...

select * from clienttbl
left outer join feestbl fee1 on = and fee1.type = type1
left outer join feestbl fee2 on = and fee2.type = type2
left outer join feestbl fee3 on = and fee3.type = type3

hope this is helpful...

Post #568911
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse