On Thu, Jan 22, 2004 at 01:01:32AM -0000, Stuart Kidd wrote: > <Table1 name: PropertyData> > PropertyDataID (Primary Key) > PropertyAgentID > PropertyReference > PropertyNumberName > PropertyStreetName > PropertyPostcodeZip > PropertyDateAdded > > I have an Agent (real person) logging in (assigned by client.agentid) > who needs to pull a list of their properties. The two tables' only > common field is PropertyDataID. > > My query to pull data from table1 is straight forward. > > <CFQUERY NAME="DisplayPropertyList" datasource="020"> > SELECT > PropertyDataID, PropertyReference, PropertyNumberName, > PropertyStreetName, PropertyPostcodeZip, PropertyDateAdded > FROM > PropertyData > WHERE PropertyAgentID = '#Client.PropertyAgentID#' > </CFQUERY> > > When I list the properties on screen I would also like to display to the > agent how many people enquired about each property. The enquiries are > kept in another database, PropertyEnquiry. > > <Table2 name: PropertyEnquiry> > PropertyEnquiryID (Primary Key) > PropertyDataID > PropertyTelephoneNumber
If you've got a decent database you can use sub-selects, such as: <CFQUERY NAME="DisplayPropertyList" datasource="020"> SELECT PropertyDataID, PropertyReference, PropertyNumberName, PropertyStreetName, PropertyPostcodeZip, PropertyDateAdded, (select count(*) from PropertyEnquiry where PropertyDataID = PropertyData.PropertyDataID) as EnquiryQty FROM PropertyData WHERE PropertyAgentID = '#Client.PropertyAgentID#' </CFQUERY> Oh, and you'll want to change the '#Client.PropertyAgentID#' to use <CFQUERYPARAM... like: <cfqueryparam value='#Client.PropertyAgentID#' CFSQLType='CF_SQL_<something_or_other'> Cheers Paul Haddon Technical Services Manager Formstar Print Technologies --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004
