junction table query

I need a query that will populate  ‘tbl_rep_region_junction’  (example below) 
with IDs from ‘tbl_rep_location’ and ‘tbl_city’ based on the entries in the 4 
code_x columns  in ‘tbl_rep_location’.  Skip all blank code_x  without region 
names. Thanks for the help..


tbl_rep_location

rep_loc_id	 repname	 code_1	code_2	code_3	code_4
1	 smith	 west	east	midwest	south
2	 james	 west			south
3	 phillips		east	midwest	


tbl_city
city_id	name	     region_id
1	Los angeles     2
2	New York	     1
3	chicago	     3
4	dallas	     4


tbl_region

region_id	 region_names
1	 east
2	 west
3	 midwest
4	 south


tbl_rep_region_junction

Junction_id   rep_loc_id   city_id
1	   1	     1
2	   1	     2
3	   1	     3
4	   1	     4
5	   2	     1
6	   2	     4
7	   3	     2
8	   3	     3



0
Utf
3/29/2010 11:13:01 AM
sqlserver.server 1327 articles. 0 followers. Follow

2 Replies
630 Views

Similar Articles

[PageSpeed] 37

Can I ask if this is a homework assignment?

-- 
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"morphius" <morphius@discussions.microsoft.com> wrote in message 
news:F92E1768-D4F4-4368-AF3C-DBA4D6838994@microsoft.com...
>I need a query that will populate  'tbl_rep_region_junction'  (example 
>below)
> with IDs from 'tbl_rep_location' and 'tbl_city' based on the entries in 
> the 4
> code_x columns  in 'tbl_rep_location'.  Skip all blank code_x  without 
> region
> names. Thanks for the help..
>
>
> tbl_rep_location
>
> rep_loc_id repname code_1 code_2 code_3 code_4
> 1 smith west east midwest south
> 2 james west south
> 3 phillips east midwest
>
>
> tbl_city
> city_id name      region_id
> 1 Los angeles     2
> 2 New York      1
> 3 chicago      3
> 4 dallas      4
>
>
> tbl_region
>
> region_id region_names
> 1 east
> 2 west
> 3 midwest
> 4 south
>
>
> tbl_rep_region_junction
>
> Junction_id   rep_loc_id   city_id
> 1    1      1
> 2    1      2
> 3    1      3
> 4    1      4
> 5    2      1
> 6    2      4
> 7    3      2
> 8    3      3
>
>
> 


0
TheSQLGuru
3/29/2010 1:45:31 PM
> Can I ask if this is a homework assignment?

You know it is Kevin.

The OP may think he is being creative in just copying the question verbatim 
to the newsgroup, just like the thousands of lazy students before him. What 
I find curious is that so many people seem to give answers anyway.

-- 
Jay Konigsberg
SQL Server DBA in Sacramento, CA
http://www.linkedin.com/in/jaykonigsberg

Live in Sacramento, CA?
Join the Sacramento SQL Server User Group on LinkedIn
http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=%2Emyg



"TheSQLGuru" <kgboles@earthlink.net> wrote in message 
news:ovadnZu_g9awMy3WnZ2dnUVZ_jWdnZ2d@earthlink.com...
> Can I ask if this is a homework assignment?
>
> -- 
> Kevin G. Boles
> Indicium Resources, Inc.
> SQL Server MVP
> kgboles a earthlink dt net
>
>
> "morphius" <morphius@discussions.microsoft.com> wrote in message 
> news:F92E1768-D4F4-4368-AF3C-DBA4D6838994@microsoft.com...
>>I need a query that will populate  'tbl_rep_region_junction'  (example 
>>below)
>> with IDs from 'tbl_rep_location' and 'tbl_city' based on the entries in 
>> the 4
>> code_x columns  in 'tbl_rep_location'.  Skip all blank code_x  without 
>> region
>> names. Thanks for the help..
>>
>>
>> tbl_rep_location
>>
>> rep_loc_id repname code_1 code_2 code_3 code_4
>> 1 smith west east midwest south
>> 2 james west south
>> 3 phillips east midwest
>>
>>
>> tbl_city
>> city_id name      region_id
>> 1 Los angeles     2
>> 2 New York      1
>> 3 chicago      3
>> 4 dallas      4
>>
>>
>> tbl_region
>>
>> region_id region_names
>> 1 east
>> 2 west
>> 3 midwest
>> 4 south
>>
>>
>> tbl_rep_region_junction
>>
>> Junction_id   rep_loc_id   city_id
>> 1    1      1
>> 2    1      2
>> 3    1      3
>> 4    1      4
>> 5    2      1
>> 6    2      4
>> 7    3      2
>> 8    3      3
>>
>>
>>
>
> 


0
Jay
3/30/2010 4:46:14 AM
Reply:

Similar Artilces:

Pivot Table Source Data
I have an existing Pivot Table that usually updates daily, albeit this relies someone in the office refreshing the data. Anyway we seem to have missed one days data and thought we would be clever and just include the days missing data back into the source data. In effect we are putting the 8th September data between the 7th and the 9th. However no matter what we do the data from the 8th ends up as the last column in the pivot table. Are we missing something really simple here or has my brain turned to mush? thanks for the help in advance. Bryan P.S I also tried creating a dynamic range but ...

Help with SQL Query 06-30-10
We have a distinct list of email addresses in alpha order and we need to transform it from a single column into a grid of three columns maintaining the alpha order. The list is contained in a temp table inside of our query. We then use the temp table list and perform case statement with a mod on the row_number in a select statement to columnze the data. However, the columnar data contains a null value in two of the three columns and we are needing to remove the nulls and have the actual values on each row in the output. Here is our current sql: CREATE TABLE #tmpTable ( Email_Add...

Sales Distribution Entry table
Can someone point me at the table that stores the data for the Sales Distribution Entry window? Thanks. On Feb 27, 10:44=A0am, ALGP <gpjef...@gmail.com> wrote: > Can someone point me at the table that stores the data for the Sales > Distribution Entry window? > > Thanks. SOP10102 ...

Round up a decimal in a query field
Hopefully this is an easy question. How do you round up a number in a query field? Excel has the ROUNDUP function, but I can't find anything similar in Access. Can anyone help? Function:round([tablename!fieldname,2]) I think. It may be round([tablesname!fieldname],2) "bigomega73" wrote: > Hopefully this is an easy question. How do you round up a number in a query > field? Excel has the ROUNDUP function, but I can't find anything similar in > Access. Can anyone help? Thanks Golfinray, but that only rounds to the nearest decimal place. What I want is the numb...

pivot table grand totals not showing for all columns...
i have a pivot table that shows the grand total for some columns, but not for others... there are no differences in the data layout, yet this happens? any clues as to why? and how I can get the grand totals to show for all fields. thanx in the PivotTable floating toolbar, click PviotTable, then Table Options, select 'Grand totals for columns' option. ...

Grouping dates in pivot table
I am pulling data from a SQL Server database to create a pivot table. Excel (07) is not recognizing the field as a date. This is a field I would like to group by in the pivottable. I am aware of all the techniques to convert this to a date field, but I am searching for an answer as to why XL pivot tables cannot consume the dates directly from a sql query. I have played with bringing the dates back in a number of differenent formats with no success. Any insights into this would be appreciated. Probably coming in as text and yuo may only need to copy an unused cell and paste sp...

Query by Form Problem 06-19-07
I'm using QBF with about six different combo boxes using: [forms]! [formmain]! [combo1] or [forms]![formmain1]![combo1] -like in a VBA book. This is so users can select criteria on a form with the combo boxes, and when they are done, they hit the search button, and it opens up another form based on the query just performed by the combo selection. This worked for about three combo boxes, but when I added another one, it freezes up and opens up a blank page. It's supposed to open the new form based on the query. Is there a better way to do this? I've looked exhaustive...

SQL Query
I'm trying to create a query that will result in receipt transaction details from POP10310 combined with GL transactions from GL20000 and so far no success. I assume I also need POP10300 in the mix. Which field(s) should I be joining between GL20000 and POP10300 or PO10310? Thanks. Frank Hamelly, MCP-GP NOVA Solutions LLC Melbourne, FL Try using POP30310 instead. The receipt transactions would have to be posted before anything got to GL20000. -- Jim@TurboChef "Frank Hamelly, MCP-GP" wrote: > I'm trying to create a query that will result in receipt transaction &...

Table name length in microsoft query
Hi! Is it true that the maximum length of a tablename is still 8 characters. I'm useing Excel 97 and trying to get data from a Paradox 9 table via odbc-link and Microsoft Query. I have heard a few years ago that long names are OK and supported all over the microsoftian regime. Is there any trick to avoid this without shortening all the names. Greetings from Helsinki HK ...

Data Tables
In Excel 2000, must data tables (Data\Tables...) always be located on the same worksheet tab as the source data? I want to put summary tables into a separate worksheet (tab), but Excel won't let me do that. Steve Looks that way, at least in Excel97 (my ver) But we could always mirror the data tables (or parts thereof) elsewhere (eg: another sheet) via simple link formulas -- Rgds Max xl 97 --- Singapore, GMT+8 xdemechanik http://savefile.com/projects/236895 -- "Steve D" <sdrenker_(you_know_what_here)_media.sj.nec.com> wrote in message news:ufhMsZfyFHA.3804@TK2MSFTNGP10....

Query-based distribution group anomaly
When I do a TOOLS ~ OPTIONS ~ DELEGATES in Outlook 2003 and try to set a query-based distribution group as a delegate it seems to accept the group and whatever permissions I assign. But as soon as I click OK and then come back in to inspect it, the query-based distribution group has no permissions at all. This happens every time. However, in the same situation, whenever I assign a Global Security Group as a delegate and assign permissions, they stick. Should my query-based distribution group be accepted or is this kind of group not permitted as a delegate? But then if it's not perm...

Pvt Table Question
I am creating several pvt tables that will be updated often with new data. I want to know if there is any function within a pvt table that I can use to set up my pvt table so that only the top 10 data points are automatically displayed. So for example, if i have pvt table set up to show brand name and then accounts for each brand name and I sorted on accounts descending and only wanted the pvt table to show the top 10 brands that had the highest total accounts. Is this possible? Thanks. Hi, To show the top 10 values for a field - double-click the field heading, click 'Advanced' ...

Formatting number in Data Table
I am using Excel 2007. I have a spreadsheet that the figures can be negative or positve. I have formatted the cells with this custom format $#,##0;[Red]$-#,##0. On the spreadsheet the format works fine. I created a chart from the data. I have a data table at the bottom of the chart. The problem is that the format from the spreadsheet is not reflected in the data table. When I click on Format Data Table, there is no option for number formatting. There is a number formatting option available when i click Format Axis, but this doesn't change it, because the actual axis is Text. Is th...

Table relationships
I've created a database with about 15 tables for a participant data in a research study. Each participant will complete the 15 assessment measures. My ultimate goal is to create a data entry system whereby a research assistant can pull up a form and enter an ID number, plus the answers to the 15 assessment measures. I know I can create a query to combine all the tables, but it seems like the research assistant would have to enter the id and date 15 times (once for each table pulled in to the query). Is there a way to just enter the ID number one time and have it apply t...

Random List from Query
For accrediation purposes we have to audit a random 10% of our cases each quarter I was wondering if there is a way to run a query or report that would let me show a random 10% of cases for a specific provider. ...

Adding a total row to a chart data table
I have the following data in a chart Week 1 2 3 4 5 6 7 8 Data1 1 5 7 6 1 6 7 6 Data2 3 4 5 7 9 4 6 6 Is it possible to have the data table show a totals row? I.E: Totals 4 9 12 13 10 10 13 12 Thanks in advance, John You can't include the total in the data table. As a workaround, you could embed the chart on a worksheet, and display the data below it. Tushar Mehta has instructions on his web site: http://tushar-mehta.com/excel/newsgroups/data_table/index.htm John Ortt wrote: > I have the following data in a chart > > Week 1 2 3 4 5 6 7 8 > Data1 1 5 7 6 1 6 7 6...

Need to find the table
I do get some odd requests for great plains. My latest requires me to track down a table. The one i need is for one of the forms that shows in the smart list. I need the one under account transactions and is called Output VAT Nominal. I need to know what table/s supply this form. Even better would be if it was possible to access the hard coding of this form. I looked for it and found nothing. We run great plains version 8 should it help. well, thankyou all kindly in advance. Tools>Resource Descriptions is always a good place to start. "Saltious" wrote: > I do get som...

pivot table 05-01-10
I have data on two worksheet and i want to analize data by consolidate them togeter.How can i use pivot table? -- meihua meihua;950632 Wrote: > I have data on two worksheet and i want to analize data by consolidate > them > togeter.How can i use pivot table? > > -- > meihua Option 1. Yes, you can use mutliple sheets connected to single pivot. choose, Multiple consolidation ranges option in Pivot table and Pivot Chart Wizard - step 1 of 3. Option 2. It is better to get the all data into single sheet and use pivot. thanks bala --...

Form now Sub-Form, Query Broken
I recently posted this problem in "Forms" (Lost Focus of Form 7/27) thinking that was the problem, but recently discovered the problem appears to be in the query(ies). I've dropped a from into a form that has multiple tabs/pages to consolidate things. The other - now sub-forms still function as before, but this one retrieves records from the archive and drops them in the the main employee table. The following pops up as an input box - Forms.Archive.track I found this in one of the queries where: Field: Track - its the unique identifier for the employee table Table: E...

Formula Result Won't Query
Hi All, I have a range of cells and some of them contain this formula: =IF($C$1="Glamour","15.688",IF($C$1="Econo","15.563","Select Style")). The problem I have is when I query this range on another work sheet, it leaves the results of any cells with this formula blank. It is important to me to have this formula in the cell, do you have any suggestions. Sincerely, Nathan Sargeant -- natei6 ------------------------------------------------------------------------ natei6's Profile: http://www.excelforum.com/member.php?action=getinfo&a...

Reporting table fields vertically
I've come across a client with a non-normalized table with sales of items for eight different regions. So, the fields in the table are: ItemCode Region1SalesQty Region2SalesQty .... .... Region8SalesQty Typically the client is printing these sales in columns, with a report that has the eight regions spaced horizontally across the page. Something like this: ItemCode Region1SalesQty Region2SalesQty ... Region8SalesQty However, they now need a report with the sales reported vertically, like this: ItemCode Region1SalesQty Region2SalesQty ...

Emailing information from a query
I would like to email the information from a query in the body of my email message, Ex. Query Name.emaildates with the following 3 fields id# date due assigned to 0001 05/01/2007 M. Smith 0002 05/02/2007 J. Smith etc Can someone please help. I looked at http://www.granite.ab.ca/access/email/formatted.htm. but that totally confused me. ...

Update Query
I have 2 tables: Member and Bulk Mail I have linked them on Last Name Member has these fields: First Name, Last Name, E-mail Bulk mail has these fields: First Name, Last Name, e-mail address The member table has no data in the E-mail field The Bulk Mail table has data in the e-mail address field I would like to update the Member E-mail field with the data in the Bulk Mail e-mail address field using the Query Wizard Glenn Glenn T. Dulmage 207 Valley Road Chestertown, MD 21620 410-778-5166 gdulmage@verizon.net Glenn So, you quite certain that you don't have and ...

Deleting Import Error Tables
Is there a way to delete a series of import error tables programatically? I am pulling in unformatted data from Excel, which causes many import error tables... The data is good, just not formatted to directly load into a table. I would like to regularly programatically delete these import error tables, otherwise they just continue to accumulate. Thank you, I can't remember the naming convention for the import error tables. What do they look like? -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele (no e-mails, please!) "Cathy" <Cat...

VBA variable to population Table Question
I am using the following code to fill a line in one of my tables based off what someone enters into a text box. The problem is whenever the code runs a popup dialog box comes up asking the user to enter the variable values over again. How can I set it up so the values are just taken from the text box instead of being asked for in the dialog window? DoCmd.SetWarnings False DoCmd.RunSQL ("INSERT INTO Keywords (ReferenceID, Keyword) VALUES (RefID, KeyPart)") DoCmd.SetWarnings True "Zachary" <zlehmann@gmail.com> wrote in message news:a40e9e56-e8b9-48e2-80e1-cb2...