Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pareshmotiwala
Constraint Violating Yak Guru
323 Posts |
Posted - 2007-03-02 : 11:45:58
|
| I have two tables A and B. A is for Agent and B for Clients.A can have multiple clients and B can have multiple Agents.Agents have to pay for all clients and Clients have to pay for all Agents(don't ask me why).So, if I have to find out the complete payment scene. I have to say Select * from A .... join B.AgentID=A.AgentId and then----Select * from B.... where A.agentId=B.AgentId.I had recommended having a table AB which would have the AgentID mapped to Clients..and a Table BA which would have the ClientID mapped to Agents....Question is, is that the right thing to do or anybody have any other ideas? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-02 : 11:48:44
|
this is a bit confusing. Can you post your table structure, some sample data and the result that you want ? KH |
 |
|
|
pareshmotiwala
Constraint Violating Yak Guru
323 Posts |
Posted - 2007-03-02 : 11:59:07
|
quote: Originally posted by khtan this is a bit confusing. Can you post your table structure, some sample data and the result that you want ? KH
I have PMed it to you sir |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-02 : 12:04:46
|
quote: Hello khtanYou received the following message from: pareshmotiwalaAt: http://www.sqlteam.com/forums/SELECT dbo.tblRegistrationComplete.strType, dbo.tblRegistrationComplete.strID, dbo.tblEmployDetailsComplete.strID AS Employ_strID, dbo.tblEmployDetailsComplete.strType AS Employ_strTypeFROM dbo.tblRegistrationComplete INNER JOIN dbo.tblEmployDetailsComplete ON dbo.tblRegistrationComplete.RegID = dbo.tblEmployDetailsComplete.RegIDWHERE (dbo.tblRegistrationComplete.strPeriodTitle = '2006') AND (dbo.tblRegistrationComplete.strID = '0084')SELECT dbo.tblRegistrationComplete.strType, dbo.tblRegistrationComplete.strID, dbo.tblEmployDetailsComplete.strID AS Employ_strID, dbo.tblEmployDetailsComplete.strType AS Employ_strTypeFROM dbo.tblRegistrationComplete INNER JOIN dbo.tblEmployDetailsComplete ON dbo.tblRegistrationComplete.RegID = dbo.tblEmployDetailsComplete.RegIDWHERE (dbo.tblRegistrationComplete.strPeriodTitle = '2006') AND (dbo.tblEmployDetailsComplete.strID = '0084')
Can you post the table structure here with sample data and result that you want. KH |
 |
|
|
pareshmotiwala
Constraint Violating Yak Guru
323 Posts |
Posted - 2007-03-02 : 12:36:51
|
| tblEmployDetailsComplete Table B========================== Ordinal Position Column Name Type1 EmpID decimal2 RegID decimal3 strID varchar4 strType varchar5 strFName varchar6 strMInitial varchar7 strLName varchar8 strCorpName varchar9 strAddr varchar10 strAddr2 varchar11 strCity varchar12 strState char13 strPostalCode varchar14 strPhone varchar15 dteDateOfEmploy datetime16 dteTerminateDate datetime17 strDuration varchar18 strBusnIntent varchar19 strEmail varchar20 strEmployee varchar21 strIndirectLobbyist varchar22 strWaiverNonProfitType varchar23 IsPaid bit24 dteUpdated datetime25 strPage chartblRegistrationComplete Table A=======================1 RegID decimal2 strID varchar3 strtype varchar4 strPeriodTitle varchar5 strStatus varchar6 strStatusReason varchar7 strWaiverStatus varchar8 strWaiverDesc varchar9 strEmail varchar10 strEmailOptOut char11 strFName varchar12 strMInitial varchar13 strLName varchar14 strNameTitle varchar15 strCorpName varchar16 strPhone varchar17 strBusnAddr varchar18 strBusnAddr2 varchar19 strBusnCity varchar20 strBusnState char21 strBusnPostalCode varchar22 strBusnCountry varchar23 strResAddr varchar24 strResAddr2 varchar25 strResCity varchar26 strResState char27 strResPostalCode varchar28 strResCountry varchar29 strUpdateID varchar30 strCatID varchar31 strSSN varchar32 strBusnIntent varchar33 strWaiverNonProfitType varchar34 strComment varchar35 strContact varchar===================================All persons from Table A, can have multiple Employees, for whom he would or would not have paid. Similarly an Employee from Table B could have hired services of a person or persons from Table A. and not paid for corresponding number of people.So What i want to find is When a person from Table A logs in, not only does he see the corresponding clients which he has registered from table B, but also the client who have registered him but not yet paid for this person.I wouldn't mind having Unions on this..but currently since this table only has 2000 rows, we are living easy. But this may swell up soon. So the question is an intermediate table or better indexing?Hope this helps. |
 |
|
|
|
|
|
|
|