two variables

I have a query that asks for collcode, collcode2 and booth.  On any given day 
an employee may be collcode or collcode2.  I would like to know how many 
times a certain emp has been paired with another employee.  So how do I ask 
if an employee has been collcode/collcode2 and who the other person was?  I 
hope this question makes sense.

Thanks for any help
0
Utf
10/14/2007 1:50:00 PM
access.queries 6343 articles. 1 followers. Follow

4 Replies
1164 Views

Similar Articles

[PageSpeed] 49

Query one:
SELECT CollCode, CollCode2, Booth
FROM YourTable
UNION ALL
SELECT CollCode2, CollCode, Booth
FROM YourTable


Query Two
SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
FROM QueryOne
GROUP BY CollCode, CollCode2

IF you want to limit the result to a specific individual then add a 
where clause

Query Two
SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
FROM QueryOne
WHERE CollCode = "SomeValue"
GROUP BY CollCode, CollCode2

If you want to list every incident and the booth
SELECT CollCode, Callcode2, Booth
FROM QueryOne
WHERE CollCode = "SomeValue"




'====================================================
  John Spencer
  Access MVP 2002-2005, 2007
  Center for Health Program Development and Management
  University of Maryland Baltimore County
'====================================================


margaret wrote:
> I have a query that asks for collcode, collcode2 and booth.  On any given day 
> an employee may be collcode or collcode2.  I would like to know how many 
> times a certain emp has been paired with another employee.  So how do I ask 
> if an employee has been collcode/collcode2 and who the other person was?  I 
> hope this question makes sense.
> 
> Thanks for any help
0
John
10/14/2007 2:15:59 PM
John:

That worked great, thanks for your prompt response.  However, one more 
variable.  The employees will count  many booths on one day, for example, the 
team may count booth 1, 2, 3, 4.  So I need to limit the count to how many 
"fairdate" they were matched instead of how many times they were together.

FYI, the table is:  id, collcode, collcode2, booth, fairdate ... Sorry I 
know I didn't mention fairdate last time.

"John Spencer" wrote:

> 
> Query one:
> SELECT CollCode, CollCode2, Booth
> FROM YourTable
> UNION ALL
> SELECT CollCode2, CollCode, Booth
> FROM YourTable
> 
> 
> Query Two
> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
> FROM QueryOne
> GROUP BY CollCode, CollCode2
> 
> IF you want to limit the result to a specific individual then add a 
> where clause
> 
> Query Two
> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
> FROM QueryOne
> WHERE CollCode = "SomeValue"
> GROUP BY CollCode, CollCode2
> 
> If you want to list every incident and the booth
> SELECT CollCode, Callcode2, Booth
> FROM QueryOne
> WHERE CollCode = "SomeValue"
> 
> 
> 
> 
> '====================================================
>   John Spencer
>   Access MVP 2002-2005, 2007
>   Center for Health Program Development and Management
>   University of Maryland Baltimore County
> '====================================================
> 
> 
> margaret wrote:
> > I have a query that asks for collcode, collcode2 and booth.  On any given day 
> > an employee may be collcode or collcode2.  I would like to know how many 
> > times a certain emp has been paired with another employee.  So how do I ask 
> > if an employee has been collcode/collcode2 and who the other person was?  I 
> > hope this question makes sense.
> > 
> > Thanks for any help
> 
0
Utf
10/14/2007 3:08:00 PM
Try the following

Query One:
SELECT CollCode, CollCode2, FairDate
FROM YourTable
UNION
SELECT CollCode2, CollCode, FairDate
FROM YourTable

Using UNION instead of UNION ALL will remove any duplicates in the results.

Query Two (use query one as the basis)
SELECT CollCode, CollCode2, Count(FairDate) as DayCount
FROM QueryOne


'====================================================
  John Spencer
  Access MVP 2002-2005, 2007
  Center for Health Program Development and Management
  University of Maryland Baltimore County
'====================================================


margaret wrote:
> John:
> 
> That worked great, thanks for your prompt response.  However, one more 
> variable.  The employees will count  many booths on one day, for example, the 
> team may count booth 1, 2, 3, 4.  So I need to limit the count to how many 
> "fairdate" they were matched instead of how many times they were together.
> 
> FYI, the table is:  id, collcode, collcode2, booth, fairdate ... Sorry I 
> know I didn't mention fairdate last time.
> 
> "John Spencer" wrote:
> 
>> Query one:
>> SELECT CollCode, CollCode2, Booth
>> FROM YourTable
>> UNION ALL
>> SELECT CollCode2, CollCode, Booth
>> FROM YourTable
>>
>>
>> Query Two
>> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
>> FROM QueryOne
>> GROUP BY CollCode, CollCode2
>>
>> IF you want to limit the result to a specific individual then add a 
>> where clause
>>
>> Query Two
>> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
>> FROM QueryOne
>> WHERE CollCode = "SomeValue"
>> GROUP BY CollCode, CollCode2
>>
>> If you want to list every incident and the booth
>> SELECT CollCode, Callcode2, Booth
>> FROM QueryOne
>> WHERE CollCode = "SomeValue"
>>
>>
>>
>>
>> '====================================================
>>   John Spencer
>>   Access MVP 2002-2005, 2007
>>   Center for Health Program Development and Management
>>   University of Maryland Baltimore County
>> '====================================================
>>
>>
>> margaret wrote:
>>> I have a query that asks for collcode, collcode2 and booth.  On any given day 
>>> an employee may be collcode or collcode2.  I would like to know how many 
>>> times a certain emp has been paired with another employee.  So how do I ask 
>>> if an employee has been collcode/collcode2 and who the other person was?  I 
>>> hope this question makes sense.
>>>
>>> Thanks for any help
0
John
10/14/2007 9:10:22 PM
Wonderful ... thank you for your help today.  It now works like a champ.

"John Spencer" wrote:

> Try the following
> 
> Query One:
> SELECT CollCode, CollCode2, FairDate
> FROM YourTable
> UNION
> SELECT CollCode2, CollCode, FairDate
> FROM YourTable
> 
> Using UNION instead of UNION ALL will remove any duplicates in the results.
> 
> Query Two (use query one as the basis)
> SELECT CollCode, CollCode2, Count(FairDate) as DayCount
> FROM QueryOne
> 
> 
> '====================================================
>   John Spencer
>   Access MVP 2002-2005, 2007
>   Center for Health Program Development and Management
>   University of Maryland Baltimore County
> '====================================================
> 
> 
> margaret wrote:
> > John:
> > 
> > That worked great, thanks for your prompt response.  However, one more 
> > variable.  The employees will count  many booths on one day, for example, the 
> > team may count booth 1, 2, 3, 4.  So I need to limit the count to how many 
> > "fairdate" they were matched instead of how many times they were together.
> > 
> > FYI, the table is:  id, collcode, collcode2, booth, fairdate ... Sorry I 
> > know I didn't mention fairdate last time.
> > 
> > "John Spencer" wrote:
> > 
> >> Query one:
> >> SELECT CollCode, CollCode2, Booth
> >> FROM YourTable
> >> UNION ALL
> >> SELECT CollCode2, CollCode, Booth
> >> FROM YourTable
> >>
> >>
> >> Query Two
> >> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
> >> FROM QueryOne
> >> GROUP BY CollCode, CollCode2
> >>
> >> IF you want to limit the result to a specific individual then add a 
> >> where clause
> >>
> >> Query Two
> >> SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED
> >> FROM QueryOne
> >> WHERE CollCode = "SomeValue"
> >> GROUP BY CollCode, CollCode2
> >>
> >> If you want to list every incident and the booth
> >> SELECT CollCode, Callcode2, Booth
> >> FROM QueryOne
> >> WHERE CollCode = "SomeValue"
> >>
> >>
> >>
> >>
> >> '====================================================
> >>   John Spencer
> >>   Access MVP 2002-2005, 2007
> >>   Center for Health Program Development and Management
> >>   University of Maryland Baltimore County
> >> '====================================================
> >>
> >>
> >> margaret wrote:
> >>> I have a query that asks for collcode, collcode2 and booth.  On any given day 
> >>> an employee may be collcode or collcode2.  I would like to know how many 
> >>> times a certain emp has been paired with another employee.  So how do I ask 
> >>> if an employee has been collcode/collcode2 and who the other person was?  I 
> >>> hope this question makes sense.
> >>>
> >>> Thanks for any help
> 
0
Utf
10/14/2007 9:36:01 PM
Reply:

Similar Artilces:

synchiing two computers?
Is there a way to synch Outlook on two computers? I end up with some email on my laptop and some on my desktop - it would be nice if the two could be synched so that I could have all of my email on both computers. Take a look here, it may help: http://www.slipstick.com/outlook/sync.htm -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. After furious head scratching, Bill Andersen asked: | Is there a way to synch Outlook on two computers? | I end up with some...

selecting and inserting existing and non existing rows into table parameters and variables
I need to do the following: 1. Select all rows that exist both in the TVP @Headlines and in the table [Headlines].[Headlines] and insert them into a table variable @ExistingHeadlines. 2. Select the rows that exist only in the TVP @Headlines and not in [Headlines].[Headlines] and insert them into a table variable @NonexistentHeadlines. How would you do this? The stored procedure takes 2 totally different paths depending on whether or not the items in @Headlines already exist in the main Headlines table. 1. If they exist already, return an error telling the client that thes...

Compare two cells in two different files and return answer
I am attempting to compare two text cells and if they both exist, I want to bring in a "yes" answer. If they don't, bring in a "no" answer. Here's an example of text. File 1 Col A Col B BRATTA ZPB_COMMON AHERNC ZPB_COMMON GENCABH ZPB_COMMON File 2 Col A Col B BRATTA ZPB_COMMON AHERNC ZPB_COMMON GENCABH So, what I want to do is say in File 1 take cells A1 and B1 compare them to File 2 and search Col A and Col B and if there is an exact mat...

Pivot table for two different data variables
I have the following table Name type Cost overhead amy C1 23 12 bob C2 129 17 cat C2 36 45 doo C2 100 32 I owuld like to create a pivot table that looks similar to: the standard pivot table. (Please ignore type for now.) name Data Total amy Sum of overhead 200 Sum of cost 12 bob Sum of overhead 130 Sum of cost 23 cat Sum of overhead 90 Sum of cost 19 doo Sum of overhead 87 Sum of cost 34 Total Sum of overhead 507 Total Sum of cost 88 But with overall total (overhead + cost) for ...

COUNTIF (?) on two criteria
I have a spreadsheet that logs work activities and records team members' completion of project units. Column B records team member names. Column C has project unit status - 'pending', 'beta' or 'completed'. It's easy to set up a formula to count how many units are allocated to each team member - =COUNTIF(B1:B1000,"Joe"). But what I need to do is set up formulas to count how many units Joe has completed, or has pending or at beta, and this means assessing data in both columns - which COUNTIF won't do. This doesn't strike me as an especially...

Two IF Statements with two answers
In cell J9 I need a formula that would do the following: If G9="Yes" then F9, If G9="No" then -f9 Note: G9 has a drop down list with Yes, No answers. If there are no other alternatives that yes and no =IF(G9="Yes",F9,-F9) otherwise =IF(G9="Yes",F9,IF(G9="No",-F9,"") Regards, Peo Sjoblom "heater" wrote: > In cell J9 I need a formula that would do the following: > > If G9="Yes" then F9, If G9="No" then -f9 > > Note: G9 has a drop down list with Yes, No answers. > =IF(G9=&qu...

Two axis
Positioning the Vertical axes: I have a chart where there are two axes. The first implementation produced the two scales on the right side, one inside, the other outside the chart area. Unusual, but luckily it fits well the chart. I tried to duplicate the feat with another dataset (similar in structure) and did not even get the second scale to show right, left or center (data plotted with two different scales allright). Where is the info to control these functionalities? Tx, Pierre On Wed, 29 Oct 2003 17:48:13 +0100, pl.carry <pl.carry@wanadoo.fr> wrote= : > Positioning the Vertic...

Variables in WHERE clause
I am using SQL Server 2005 and the T-SQL below to select records. If I type in the WHERE clause values (as shown) the query time is 1 second or less. If I use the variables @YearStart and @EndDate in the WHERE clause the query takes 33 seconds. Can someone explain and give me an alternative? Thanks. DECLARE @StartDate datetime; DECLARE @EndDate datetime; DECLARE @YearStart datetime; DECLARE @ItemId varchar(24); SET @StartDate = '8/1/2010'; SET @EndDate = '8/31/2010'; SET @YearStart = '1/1/2010'; SET @ItemId = null SELECT D.PartId, MIN(I.Desc...

plot two groups of numbers on one series of xy coordinates.
how to create a plot from separate x and y values. i.e. y values do not correspond to the same set of x values. example x1= 5, y1=10; x2= 8, y2=15 I can read your question 2 ways; A) you data looks like this x y 5 10 8 15 etc. Select the data and make an XY chart B) you have two sets of data x1 y1 5 10 10 12 17 15 21 20 and x2 y2 3 8 7 14 12 19 18 24 Make an XY chart of the first data series Select all the data (including headers) for second set, and use Copy Click the chart to activate it Use Edit | Paste Special .... indicate New Ser...

two variables
I have a query that asks for collcode, collcode2 and booth. On any given day an employee may be collcode or collcode2. I would like to know how many times a certain emp has been paired with another employee. So how do I ask if an employee has been collcode/collcode2 and who the other person was? I hope this question makes sense. Thanks for any help Query one: SELECT CollCode, CollCode2, Booth FROM YourTable UNION ALL SELECT CollCode2, CollCode, Booth FROM YourTable Query Two SELECT CollCode, CollCode2, Count(CollCode) AS TIMESPAIRED FROM QueryOne GROUP BY CollCode, CollCode2 IF y...

Find two PCI instance but load Init() one time
Hi all, I'm developing a stream interface driver for my PCI device under WinCE 6.0 and this driver works very well currently. Now, I got a problem when testing two the same PCI devices with my stream driver. The registry can find two PCI instances (i.e. PCI\Instance\mydrv1, PCI\ Instance\mydrv2) but system only call my XXX_init() one time. Does anyone know what the problem is? The following information is my registry setting: ================================================================== [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\PCI\Template\mydrv] "Dll"="myd...

Comparing two lists for matches
Hi, I am trying to do the following: There are two sets of supplier lists - A List and B List. I need to compare the two lists. Source A is my master. Source B is a subset of that but has contact information for all the suppliers. Hence, my goal is to retrieve the contact information from Source B and match it to the suppliers of Source A. The above can be easliy achieved using a vlookup funtion. But the problem is that some of the supplier names in the two lists are not exact matches. Hence, vlookup does not catch it. For instance, a supplier is listed as ABC Inc. in A list and as ABC, inc....

Compare two lists of names
Can you compare two lists of names where one list is last name first and the other is first name last? try this formual: =RIGHT(TRIM(E2),LEN(E2)-FIND(" ",E2))&" "&TRIM(LEFT(TRIM(E2),FIND(" ",E2))) it will convert First name last name to last name, first name or Visa versa. then you can compare your lists. "ea" wrote: > Can you compare two lists of names where one list is last name first and the > other is first name last? ...

Two copies of all Mailboxes
Using my sbs2003 srver with exchange 2003 installed - I notice two copies of all users mail box in the list of mailboxes using outlook 2003 on the same server. When I try to close these I get an error syaing mail boxes in use. I cn not remove them. Can you tell me how to remove these so I have just on mail box visible per user? thx Kevin Cain Class TECHNOLOGY ...

Same operations on a variable number of rows
I am posting this to both the regular and the programming group because I don't know if the solution requires programming. If not, sorry and ignore this. Anyway, here is my questions. I have a specific and then a more general issues. I have a set of data that changes frequently. In particular, the number of items change. What I want to do is get the list of unique concatenations of the items. Now that part is easy. I concatenate the cells. Copy as value. Then make a filter unique. But that is lots of action on my part. I have to copy the concatenate formula to a variable number of rows. I...

How do I create a chart on two axes with two lines and a bar
I am trying to compare two final stock prices to the average volume. So, teh left axes would have the numbers for the stock prices, and the right axes would have the volume. The two stock prices would be lines using the left, and the volume a bar using the right. I can do one line and one bar, but I can't figure out two lines. Can anyone help? Forget the built in custom types. It's better to build your own. Create your chart using all the data, to produce a chart with three line series all on the primary axis. Select the Volume series, and on the Chart menu, use Chart Type to ch...

how do I display last two digits of a SSN in a separate column
I am trying to create a formula to take an existing list of 8 or 9 digit numbers and display the last two numbers in a separate column. Is this possible? Try =RIGHT(A1,2) -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "katbone1" wrote: > I am trying to create a formula to take an existing list of 8 or 9 digit > numbers and display the last two numbers in a separate column. Is this > possible? Hi Use a formula =3Dright(A1, 2...

Combining Text and numbers from two cells
Hi all please help i have a cell with a number such as 6000 (a1) and another cell with a text aaa- and i would like to combine them in another cell to make aaa-6000, could somebody please help me with a formula? thanks Andrew -- koba ------------------------------------------------------------------------ koba's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=28639 View this thread: http://www.excelforum.com/showthread.php?threadid=492631 Hi! Try this: A1 = 6000 B1 = aaa =B1&"-"&A1 Biff "koba" <koba.1zwtbm_1134361504.8695...

Working with two Word Documents in Windowjs 7
I'm struggling to adjust to Windows 7 from XP. How do I reduce the size of two Word documents so I can view them "side by side" so to speak. The button that reduces the size of a document shrinks it to a tiny inch or so icon square in the corner of the screen. Is there no choice to view the entire document, reduced in size, when another document is on-screen? Many thanks! When you "restore" a window, it can be resized by dragging the sides. Or you can use the "snap" feature in Windows 7 to arrange windows; see http://windows.microsoft.com/en...

possible to chart two sets of data (4 columns) with common X & Y axes?
Is there a way to combine two sets of data with common X & Y axes on a scatter chart that lets the viewer see that there are two clusters of data (say with different point types or colors)? Here's an example: Column 1: Test session Column 2: Distance traveled under condition 1 Column 3: Travel time under condition 1 Column 4: Distance traveled under condition 2 Column 5: Travel time under condition 2 Columns 2/4 and 3/5 are the Y & X axes respectively. I want to overlay the raw data so that the clusters that emerge from condition 1 and 2 are easily seen (different colored dots fo...

Multiplying two columns
How do I multiply column A (length) by column B (width)? All I want is a new column C (area) where the cells correspond to what I just multiplied if one were to look from left to right. A x B = C. I can do it for two numbers but not whole columns.... In (eg) C1 =A1*B1 Select C1 Point to bottom right corner until you see the plus Double click To get the sum of all A*B you can use: =SUMPRODUCT(A1:A50,B1:B50) -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. ...

How do I print two worksheets as a two-sided document?
I am trying to print two separate worksheets from a workbook as a two-sided document. Is this possible? If so, how? Using Excel 2003. If your printer is not capable of two sided printing then I think you have to print one worksheet, flip the paper and put it back in the printer, and print the other worksheet. Brilliant, no?<g> -- Jim Rech Excel MVP "Col Flagg" <Col Flagg@discussions.microsoft.com> wrote in message news:A1298BBB-8CD8-4A0E-A49C-F71C6B28CC69@microsoft.com... |I am trying to print two separate worksheets from a workbook as a two-sided | document. Is t...

update two tables with one form
Hi, I am creating a new database and ideally would like one form only to enter the relevant data, but that means it has to update two or more tables from that. Is that possible? Thanks Christina Yes, but you need to explain your data structure a bit. In a relational database, you can have several different types of relationships. What does your form do? If you have a form that adds customers, then it would probably just update one table. If you then want to add products to your database, that would probably be a separate form. Now, when it comes time to sell a product, you would...

Two Sites / Two domains
im interested in having two domains (child i would assume) at two physical locations. I also want to have a PPTP VPN set up for replication and a path for networking both ways. Since the one domain manages AV, WSUS and other applications. The domains are the names of the family in that house. The reason for the domains are that individuals like to go through others files, we also use replication for family pictures and use of resources at each others residences. Total storage on our network is just shy of 5TB's and we also have 5 printers on the servers we all want to sh...

Pivot Table with two row header?
Can I create a Pivot Table using a combination of two rows as the header? Example: Row B1 = May_05 Row B2 = June_05 A3 thru A10 = Dates B3 thru B10 = Values I want to establish B1 & B2 together is the header row. I need to do this because C1 = May_05, C2 = Aug_05. My header is a pair of months. Does anyone know if this is possible? Thank You, Steve -- sslack ------------------------------------------------------------------------ sslack's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=16442 View this thread: http://www.excelforum.com/showthread.php...