House of Fusion
Home of the ColdFusion Community

Search cf-talk

December 02, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
   1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31       

Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

whats the best way of doing this

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Hi there
Toby King
04/15/08 05:10 A
> SELECT ct.*
Dominic Watson
04/15/08 05:32 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Toby King
04/15/2008 05:10 AM

Hi there I have an application almost complete and I'm stuck on this last part. In summary the application has been developed to allocate consultant in a management consulting company to different client jobs. i.e. I can add Consultant A to job 1 (this is being done already without any troubl). I was requested then to allow for more than 1 consultant to be allocated to a client job (this is also done - I have a drop down list where by a user can make multiple selections). In the client/job file I have a information in this table.  I have a clientid, clientjobid and also staffid fields etc.  If I have only added one staff member everything is OK.  Where I have added more than 1 staff members I am coming unstuck. I have a query SELECT * FROM tbl_clients cl, tbl_consultants ct Where cl.active = 1 AND ct.consultantid = cl.consultantid Basically the problem that I have got is that because there is more than one id in the consultantid field I am not picking up the record. Just wondering if there is a better way to do this or what people recommend. Thanks in advance.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
James Smith
04/15/2008 05:27 AM

Can't really help without more information... How are you storing consultantid in the tbl_clients table, specifically for when you have added multiples? I suspect what you really need here is a many-to-many relationship for which you will need a linking table in between your current two. -- Jay On Tue, Apr 15, 2008 at 10:11 AM, Toby King <ptanswell@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dominic Watson
04/15/2008 05:32 AM

> SELECT ct.* > FROM tbl_clients cl > INNER JOIN tbl_clientConsultants cc ON cc.clientId = cl.clientId > INNER JOIN tbl_consultants ct ON ct.consultantId = cc.consultantId > Where cl.active = 1 > Woops, that's slightly out, that will get all consultants that are assigned to active clients - but hopefully you get the jist and will be able to mold that to your needs. Dominic -- Blog it up: http://fusion.dominicwatson.co.uk

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dominic Watson
04/15/2008 05:29 AM

You need a third table to setup the many to many relationship between clients and consultants. A quick summary of the tables will look like this: tbl_consultant --------------------- PK consultantId ... tbl_client -------------- PK clientId ... tbl_clientConsultants ------------------------------ PK clientConsultantId FK consultantId FK clientId + unique constraint/index on consultantId & clientId Then the SQL to select all of a client's constultants could look like this: SELECT ct.* FROM tbl_clients cl INNER JOIN tbl_clientConsultants cc ON cc.clientId = cl.clientId INNER JOIN tbl_consultants ct ON ct.consultantId = cc.consultantId Where cl.active = 1 HTH Dominic -- Blog it up: http://fusion.dominicwatson.co.uk


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists