![]() |
|
|
| Subject:
SQL Query in MS Access
Category: Computers > Programming Asked by: jrwelch-ga List Price: $5.00 |
Posted:
05 Jun 2006 08:30 PDT
Expires: 05 Jul 2006 08:30 PDT Question ID: 735440 |
|
| There is no answer at this time. |
|
| Subject:
Re: SQL Query in MS Access
From: vbster-ga on 14 Jun 2006 08:03 PDT |
In fact I have a deceptively simple solution to your problem. This Out-of-the-box solution uses some design time changes with some simple SQL without any join stuff. Just use the lookup feature of MS-Access & get the kind of results that you are looking for by using the following method. 1. Open Companies table, "Com" in design view. 2. The following shows the property-value pair to be set in the Lookup tab of the Curr Field properties Display Control Combo Box Row Source Type Table/Query Row Source SELECT Con.ContactID, Con.ContactName FROM Con; Bound Column 1 Column Count 2 Column Widths 0";10" 3. Similarly the following shows the property-value pair to be set in the Lookup tab of the Prev Field properties. Incidentally it's exactly same as the previous one. Display Control Combo Box Row Source Type Table/Query Row Source SELECT Con.ContactID, Con.ContactName FROM Con; Bound Column 1 Column Count 2 Column Widths 0";10" 4. Save the changes. 5. Open the Com table in Datasheet view & viola! You have what you are looking for. Hope that is what you are lookin for. Thanks. |
| Subject:
Re: SQL Query in MS Access
From: nejla-ga on 14 Jun 2006 14:05 PDT |
> What I want, is a query that will get me the names of both
> (fields: Com.CompanyName, Com.Curr(joined with Con.ContactID),
> Com.Prev(joined with Con.ContactID))
> ABC Company John Smith -Unassigned-
> DEF Company Jane Smith -Unassigned-
You need a SQL statement like this:
SELECT Com.CompanyName AS CompanyName, Con1.ContactName AS CurrentContact,
Con2.ContactName AS PreviousContact
FROM Com LEFT OUTER JOIN
Con Con1 ON dbo.Com.Curr = Con1.ContactId LEFT OUTER JOIN
Con Con2 ON dbo.Com.Prev = Con2.ContactId
Hope it helps
Nejla |
| Subject:
Re: SQL Query in MS Access
From: nejla-ga on 14 Jun 2006 14:07 PDT |
I had a little mistake in my previous comment. please consider this one.
> What I want, is a query that will get me the names of both
> (fields: Com.CompanyName, Com.Curr(joined with Con.ContactID),
> Com.Prev(joined with Con.ContactID))
> ABC Company John Smith -Unassigned-
> DEF Company Jane Smith -Unassigned-
You need a SQL statement like this:
SELECT Com.CompanyName AS CompanyName, Con1.ContactName AS CurrentContact,
Con2.ContactName AS PreviousContact
FROM Com LEFT OUTER JOIN
Con Con1 ON Com.Curr = Con1.ContactId LEFT OUTER JOIN
Con Con2 ON Com.Prev = Con2.ContactId
Hope it helps
Nejla |
| Subject:
Re: SQL Query in MS Access
From: accesspro-ga on 27 Jun 2006 11:25 PDT |
Here is a simple query:
SELECT comp.compid, comp.company, comp.currcon,
DLookUp("contact","cont","contid=" & [currcon]) AS currContact,
comp.Prevcon, DLookUp("contact","cont","contid=" & [prevcon]) AS
Prevcontact
FROM [comp];
That shows following results:
compid company currcon currContact Prevcon Prevcontact
1 abc 1 john 5 david
2 def 3 abraham 2 bill
3 ghi 4 charles 1 john
4 jkl 3 abraham 4 charles
5 mno 4 charles 1 john
6 pqr 4 charles 2 bill
7 stu 2 bill 3 abraham
8 vwx 7 fred 4 charles
9 yzz 8 graham 5 david
where
*******************************
Comp: company table
having columns : Compid,Company,CurrCon,PrevCon
compid company currcon Prevcon
1 abc 1 5
2 def 3 2
3 ghi 4 1
4 jkl 3 4
5 mno 4 1
6 pqr 4 2
7 stu 2 3
8 vwx 7 4
9 yzz 8 5
**************************************
Cont: Contacts Table
having columns: ContID,Contact
contid contact
1 john
2 bill
3 abraham
4 charles
5 david
6 emma
7 fred
8 graham |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |