473,471 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Mutiple entries in a Field

RobH
56 New Member
Hi..

I have a table of Products and StateID. The products with a field for which states they are availble using the codes from the StateID table

tbl-Products
ProductID Description Available
1 "Blue Coffee Table" "1,2,3,5"
2 "Red Coffee Table" "2,3,4"


tbl-StateID
StateID State Country
1 ACT AU
2 NSW AU
3 VIC AU
4 QLD AU
5 SA AU
Note - this table will get into 2 or 3 digit StateID numbering...

I already have the Customers StateID figured out from the customers Country & State. Eg Mr John Smith Vic AU = 3

How can I have a from that has a Product Selction that only shows Products where the "3" is included in the tblProducts.Available

I know the how to have a field show the list where the entire field matches the requried Like Country = AU or State = VIC but using this normalised style and multiple entries in the one field im a little lost.
Aug 23 '07 #1
8 1320
Scott Price
1,384 Recognized Expert Top Contributor
What does the "1,2,3,5" mean in the Available field of your Products table?

It actually looks to me like this table is most certainly NOT normalized! A normalized table would only store one piece of data in one place. You have 4 pieces of data in one place...

Let us know a little more about what those numbers might mean, and we'll try to point out a little better solution.

Regards,
Scott
Aug 23 '07 #2
JConsulting
603 Recognized Expert Contributor
Hi..

I have a table of Products and StateID. The products with a field for which states they are availble using the codes from the StateID table

tbl-Products
ProductID Description Available
1 "Blue Coffee Table" "1,2,3,5"
2 "Red Coffee Table" "2,3,4"


tbl-StateID
StateID State Country
1 ACT AU
2 NSW AU
3 VIC AU
4 QLD AU
5 SA AU
Note - this table will get into 2 or 3 digit StateID numbering...

I already have the Customers StateID figured out from the customers Country & State. Eg Mr John Smith Vic AU = 3

How can I have a from that has a Product Selction that only shows Products where the "3" is included in the tblProducts.Available

I know the how to have a field show the list where the entire field matches the requried Like Country = AU or State = VIC but using this normalised style and multiple entries in the one field im a little lost.
you can use the InSTR function for that

select * from yourtable where Instr([yourfield],"3");

or

select * from yourtable where [yourfield] Like "*3*";

stuff like that
Aug 23 '07 #3
RobH
56 New Member
What does the "1,2,3,5" mean in the Available field of your Products table?

It actually looks to me like this table is most certainly NOT normalized! A normalized table would only store one piece of data in one place. You have 4 pieces of data in one place...

Let us know a little more about what those numbers might mean, and we'll try to point out a little better solution.

Regards,
Scott

The 1,2,3,5 represents the StateID number from the tblStateID so in this case..

the product with a 1,2,3,5 would be availble In the ACT,NSW,VIC & SA only
Aug 23 '07 #4
RobH
56 New Member
you can use the InSTR function for that

select * from yourtable where Instr([yourfield],"3");

or

select * from yourtable where [yourfield] Like "*3*";

stuff like that

The problem here is that when I get to a StateID of lets say 13 I dont want it to be listed as part of a search result looking for 1 or 3 because these will more than probably be a different country even.

So far here is the full listing of the tbl-StateID

tbl-StateID
StateID State Country
1 AU ACT
2 AU NSW
3 AU VIC
4 AU QLD
5 AU SA
6 AU TAS
7 AU NT
8 AU WA
9 NZ AUCKLAND
10 NZ BAY OF PLENTY
11 NZ CANTERBURY/WEST
12 NZ GISBORNE
13 NZ HAWKES BAY
14 NZ NELSON/MARLBOROGH
15 NZ NORTHLAND
16 NZ OTAGO/SOUTHLAND
17 NZ TARANAKI/WANGANUI
18 NZ WAIKATA
19 NZ WELLINGTON/MANAWA
Aug 23 '07 #5
Scott Price
1,384 Recognized Expert Top Contributor
You have a many to many relationship between tblProducts and tblStates. That means that more than one product can be related to more than one state, and vice versa.

The best way to handle this is to create a third table with the ID field for each tblProduct and tblStates. Your queries are far easier to write, and your duplication of data is far less doing this.

Regards,
Scott
Aug 23 '07 #6
RobH
56 New Member
You have a many to many relationship between tblProducts and tblStates. That means that more than one product can be related to more than one state, and vice versa.

The best way to handle this is to create a third table with the ID field for each tblProduct and tblStates. Your queries are far easier to write, and your duplication of data is far less doing this.

Regards,
Scott

The problem is with 19 states and so many products i have a table with some 16500 records. is that still going to be the best way forward?
Aug 23 '07 #7
Scott Price
1,384 Recognized Expert Top Contributor
The problem is with 19 states and so many products i have a table with some 16500 records. is that still going to be the best way forward?

That depends on how you view data integrity rules!

To my mind, yes it still is the best way. The reason being that in your products table, how are you going to update the field that contains the stateid numbers if/when a product ceases to be available in one state? Or when you wish to add a state to expand the availability of a product? Or, when a state gets swallowed up by another? Any change that gets made to that field that contains multiple values will require you to write some kind of convoluted vba code to search the database, find the wrong values and change just them, leaving the other values unchanged! (Or worse, go through by hand and try to change them manually... perish forbid!)

As I've said before, database programs are built with data integrity rules in mind. They will allow you to bend and break the rules, but you do so at your own peril...

The linking table in a many to many relationship results in the least duplication of data, is easiest to update, and is easiest to query. If you like doing things the hard way, go ahead! But don't expect many here on this site to be too keen to help you out when you run into problems :-)

Regards,
Scott
Aug 23 '07 #8
MMcCarthy
14,534 Recognized Expert Moderator MVP
The problem is with 19 states and so many products i have a table with some 16500 records. is that still going to be the best way forward?
Hi RobH

It might be worth your while reading this tutorial on Database normalisation.

Database Normalisation and Table Structures
Sep 1 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE...
1
by: Rupert Street | last post by:
I have set up a combo box that contains descriptions of work carried out. I would like if possible to click on one entry then click on another to combine both entries to make a single entry...
0
by: deepak | last post by:
i have set multiple selection property in bith listboxes(html control) to true. i have taken 2 buttons(html control) say Button1,Button2.now i want to add mutiple selected items to another listbox...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
0
by: vljones | last post by:
Hoping to find a way of entering new data into a combo box which contains a list of items contained in a table. In addition I want to allocate an ID number to entries that are not currently in...
3
poucedeleon
by: poucedeleon | last post by:
I am building a database for logging in Officers into our building. It uses a continuous form. I have added a command button labeled "Multiple Bookings. OnClick it opens a form that has two...
1
by: fformulaa | last post by:
Can't figure out how to sum up a total of hours from same date entries. Query: SELECT work_hrs_for_day.empl_numbr, work_hrs_for_day.user_date, work_hrs_for_day.workday_totl,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.