Display Foreign Field in Combo Box - database

My database is based on a cinema and features the following tables:
Movies
Customers
Ticket Information
Screenings
Bookings
I have created a combo box in the Bookings table for the Screening ID field:
This allows me to see a list of information about the cinema's screenings. The four columns that can be seen in this combo box are:
|---------------------|------------------|---------------------|------------------
| Screening ID | Screening Date | Screening Time | Movie ID
|---------------------|------------------|---------------------|------------------
| | | |
All of these fields - Screening ID, Screening Date, Screening Time and Movie ID - are fetched from the Screenings table. But, the final column, Movie ID, doesn't really do much for me. I would really like the movie name to be displayed here, as well as just the identifier, but no such field exists in the Screenings table. It does exist, however in the Movies table, see below:
(The Movies field Movie ID is referenced as a foreign key by Screenings.)
Is there any way in which I can display this field, Movie, as well as Movie ID in my combo box from the first image?

Your comboBox RowSource is currently set to Screenings
Make a new query that joins screenings and movies and assign the query as the rowSource to your combobox. Something like
Select
[Screening ID],
[Screening Date],
[Screening Time],
Movie
From
screenings inner join movies on screenings.[movie id] = movies.[movie id]

Related

DAX Measure count of customer with one specific product

I am trying to get a distinct count of my customer who purchase a specific product and show all the other product they purchased as well. I tried to put the product name in the filter, but that would not show the other products.
Customer Count = CALCULATE(DISTINCTCOUNT(CustomerKey),'Customers Products'[ProductName]'='Thigh Master').
when I show it in a table it show it like this:
Customer Name Product Name
John Doe Thigh Master
but I would like to see:
Customer Name Product Name
John Doe Thigh Master
John Doe Ab Roller
John Doe Ab Master
In your report, add 2 slicers (Customer, Product) and 2 Tables:
-First Table will have the count of how much the customer bought the selected product
-Second table will have all the products he bought. the trick is to disable the interaction between the second table and the Product slicer. that way the table won't be filtered by the selected product

Many to many relation hookup in Delphi

How do I do a many to many (master-master) relation in Delphi, I cannot find an example. Only dblookups and master-detail which I understand.
Like a product can belong to one or more categories. Like this table structure:
Product Table
ProductId, ProductName
CategoryTable
CategoryId, CategoryName
Relation table
ProductId, CategoryId
Ideally if you select a record in the product grid the edit of a product in a detail record is started in the right side of the screen. In here you can edit the product properties an ideally you can select via checkboxes one or more categories in a checkbox group/grid.
How do you hook this up with TTable of TQuery components? Is there a way?
Hope you can help!
Sincerely Edward
Some more explaination:
The goal is like:
master [product grid list] Detail [on selected product]
property **A**
property **B**
property **C**
property **D**
property **Category collection**
Category 1 - checked
Category 2 - unchecked
Category 3 - unchecked
Category 4 - checked
This can be transformed to a simple Master-Detail relation by using a joined query over Relation Table and Category Table (similar like this example):
SELECT * FROM Relation a
JOIN Category b on a.CategoryId = b.CategoryId
WHERE ProductId = :ProductId
In case you want a list of all categories where a separate field indicates if a relation to the product exists, you can use a query like this (example for MSSQL, the new field is named Checked):
SELECT c.*, CASE WHEN r.CategoryId IS NULL THEN 0 ELSE 1 END AS Checked
FROM CATEGORY
LEFT JOIN Relation r ON (c.CategoryId = r.CategoryId) AND (r.ProductId = :ProductId)
ORDER BY c.CategoryId
Note that you have to write the code to add or delete the relation record when you manipulate the check list by yourself.

MS Access - How do i use a table for a data type

Hi i am creating a contacts database and i want to use a create a cities table that i can use for the people table in the City field. How do i do this?
City table:
ID | City
--------------
1 | Wellington
2 | Auckland
3 | Christchurch
People Table Design
Field Name: City
Data Type: Short Text
Display Control: Combobox
Row Source Type: Table/Query
Row Source: City
These are my table design for the field City, but it is only showing the ID numbers in the combobox
I really am against the concept of Lookups in table. So I would suggest you to have a read of "The Evils of Lookup" before you proceed.
The problem is because you have used a table name as the RowSource. You need t modify some of the properties of the Field. In the lookup tab, change the Column Count to 2, Column Width to 0cm;2.04cm. Probably RowSource to
SELECT ID, City FROM City;

displayvalue, rowsource and rowsourcetype in foxpro 7

I have two tables customer and category, to make things simple I'll keep the structure simple :
customer
---------
id name categoryid
----------------------------------
1 joe 1
2 john 2
category
---------
categoryid categoryname
-----------------------------------
1 User
2 Admin
I have a form with customer name and some other info as text fields, and a combobox in which i would like to display the corresponding categoryname from category table.
knowing that i would like the customer table to always store the categoryid, how can i do this with foxpro databinding ? display the category name value, from category table, and store category id in customer table ?
In the form designer, combo box properties, set the RowSourceType = 2(Alias) and RowSource = "CateGory.Categoryname, CateGory.CategoryId", ControlSource = "Customer.Id", BoundColumn = 2
Also, you will want to add the tables to the DataEnvironment of the form.
In the data environment add the table which has the category which you want to view in customer form and use the category ID associated with it.
Use a combo box control to link as data source to the customer table field with the category ID, try using the combo box builder by right clicking your mouse while selecting the combo box on the form, after this is done.
Go to combo Lost Focus event and display by code the category name for the selected category in the combo box using something like this:
Getting the category and displaying it in label on form assuming that the category ID is integer:
Local iCatID As Integer
iCatID = ThisForm.Combo.Value
Select CategoryTable
Locate for iCatID = CategoryTable.CategID
IF Found()
ThisForm.Label.Caption = "Category " + Transform(CategoryTable.Category, "#T")
ThisForm.Refresh()
Else
Messagebox("Invalid Category !")
Endif
Try it out, hope it works for you.

SQL Persisted Computed Column with Subquery

I have three tables
Table 1: Items
ItemID | DaysLastSold
Table2: Listings
ItemID | ListingID
Table3: Sales
ListingID | DateItemClosed
I got this query to work:
SELECT min(DATEDIFF(day, DateItemClosed, getdate())) as DaysLastSold
from Sales
where QtySold > 0
and ListingID in (SELECT ListingID from Listings where ItemID = 8101 )
What I'm trying to do is basically place this query into the DaysLastSold Column in the Items table. So when ever the column is selected it recalculates DaysLastSold using the ItemID in the neighboring column.
If you want to persist that information you could create an indexed view that is made up of your calculated value and an ItemID. Obviously this would not be a column in your original table though. You could then join in on this view when you need the information.
Personally I would probably just do it inline when you need it. If you are concerned about performance, post the execution plan here and we may be able to make some suggestions.

Resources