From: morphius on
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



From: TheSQLGuru on
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(a)discussions.microsoft.com> wrote in message
news:F92E1768-D4F4-4368-AF3C-DBA4D6838994(a)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
>
>
>


From: Jay Konigsberg on
> 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(a)earthlink.net> wrote in message
news:ovadnZu_g9awMy3WnZ2dnUVZ_jWdnZ2d(a)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(a)discussions.microsoft.com> wrote in message
> news:F92E1768-D4F4-4368-AF3C-DBA4D6838994(a)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
>>
>>
>>
>
>