Can I create a many to many relationship in SSAS in this case:
Recursive table – key, parent_id
Table containing key from the recursive table and key from measures table
Measures table
Steps I take:
Create a cube without the recursive table dimension
Add new measure of counting rows of the bridge table
Add new dimension of the recursive table
When I try to set up Dimension Usage of the Recursive Table to Many to Many with Measures table it tells me that no intermediate measures group or dimension table exists where I have created it in point 2
Links in SSAS:
RecursiveTable --> BridgeTable <-- MeasuresTable
CustomerTable Bridge MeasureTable
Id(PK) CustId(PK) Id (PK)
CustomerId Id CountMeasure
ParentId
DepName
Related
I have three tables for a mock/fake database I am creating to learn SQL
Purchases
PK Purchase_ID
FK Creditcard_ID
Order_Date
Products
PK Product_ID
Product
Description
Cost
Purchases_Products
PK Purchases_Products_ID
FK Purchase_ID
FK Product_ID
Quantity
Review
I want to add a View column under Purchases, Total_Cost, that computes this value:
Summation[Product_ID]_(Purchases_Products.Quantity * Products.Cost)
Which sums over all products belonging to a single Purchase_ID. This will require a join. How may I accomplish this?
(edit: While learning how to use a join in a constraint for a Junction Table to prevent null values in parent tables was a great read and something I may want to implement, I still do not understand my question any better sadly.)
I am trying to merge two tables with financial information about the same list of stocks: the first is the prices table (containing, daily, weekly, monthly, etc... price data) and the second is the ratios table (containing valuation and other ratios). Both tables have identical primary key numerical ID columns (referencing the same stock tickers). After creating a connection cursor cur, My code for doing this is:
CREATE TABLE IF NOT EXISTS prices_n_ratios AS SELECT * FROM
(SELECT * FROM prices INNER JOIN ratios ON prices.id = ratios.id);
DROP TABLE prices;
DROP TABLE ratios;
This works fine except that the new prices_n_ratios table contains an extra column named ID:1 whose name is causing problems during further processing.
How do I avoid the creation of this column, maybe by somehow excluding the second tables's first primary key ID column from * (listing all the column names is not an option), or if I can't, how can I get rid of this extra column from the generated table as I have found it very hard to delete it in SQLite3?
Just list all the columns you actually want in the SELECT clause, instead of using *.
Alternatively, join with the USING clause, which automatically removes the duplicate column:
SELECT * FROM prices JOIN ratios USING (id)
I need some guidance on designing the schema for invoices in a multi-tenant application.
I have a table called EmployeePay which holds all the information required to generate an invoice. The invoice table would have the invoice number, invoice created date and VAT rate. I am thinking to create a Sequence object for each Tenant to generate an invoice number.
EmployeePay Table: EmployeeID, Hours, Rate, InvoiceID (FK)
Invoice Table: InvoiceID (PK) (Identity), InvoiceNumber, InvoiceDate, VATRate, TenantID
Is it okay to have hundreds of Sequence objects in a database, as I’ll have to create one for each tenant? I’ll also have to create same amount of stored procedures which returns the next invoice number (I prefer a separate stored procedure for each tenant rather than having one large stored procedure with hundreds of choices in a select case statement).
Another concern is, is it theoretical to insert into the master table (Invoice) based on the transaction table (EmployeePay) and then use its primary key(InvoiceID) to update the transaction table?
Thanks in advance.
First make sure the relationship either this is one to many or many to many. If you are considering one employee that will have many invoices then its one to many relationship and you can create your table as under:
EmployeePay Table: EmployeeID (PK) (Identity), Hours, Rate
Invoice Table: InvoiceID (PK) (Identity), EmployeeID (FK), InvoiceNumber, InvoiceDate, VATRate, TenantID
EDIT:
I don't know which database you are using but for increment sequence check:
for MySQL check this LINK.
If you are using Oracle then check this LINK
I would suggest you to create another table can be called as InvoiceNumber, this will contain InvoiceNumberId(Int),TenantId (Fk), CurrentSequenceNumber(Int).
Significance of CurrentSequenceNumber is that it will be simple integer number which can be used to generate next Invoicenumber.InvoiceNumberId will be a Identity columns for Primary key purpose (you may or may not have it).
Structure of the Table will look like below.
Now you need to create only One Stored Procedure which will take input parameter as TenantId and will have responsiblity to generate next Invoice number by reading CurrentSequenceNumber from above table.
For example if we need to generate new Invoice Id for Tenant with id as 15 then SP will have your Business logic I am assuming Just creating a String with "Inv-" as prefix with incremented value of CurrentSequenceNumber so output of Procedure will be.
Inv-0009
Then after generation of this number SP will increment value to 9 for InvoiceNumberId 3.
So everything will be managed by Single table and Single procedure only.
I am fairly green when it comes to working with Access and databases in general.
I am asking for your help in figuring out how to set the correct relationships for three tables:
Table 1 contains:
(no unique ID)
SalesTripID
EmployeeName
StartDate
EndDate
*Each record on this table is related to 1 specific employee's 1 specific sales trip
Table 2 contains:
HotelName
HotelStart
HotelEnd
HotelTotal
*This table may contain multiple records that belong to only 1 record on table 1 (for instance, an employee would stay at 2 hotels during their sales trip)
Table 3 contains:
(no unique ID)
MealVendor
MealDate
MealTotal
*This table, similar to Table 2, may have multiple records in it that are tied to the 1 SalesTripID
How do I set something up to show me each SalesTripID, the multiple Table 2, and the multiple Table 3 records associated with it? Do I need to add a Primary Key anything other than Table 1? Is writing a query involved to display the information? Because I am so green, any and all feedback is welcome.
The following is my recommendation:
Add a SalesTripId field on tables 2,3. This is called a ForeignKey.
If SalesTripId in Table1 is not unique (i.e. each employee can have a trip with the same Id as another employee), add another field (Id) in Table1. You can use Access' AutoNumber type for that field.
I recommend always having a primary key in your tables. But you can skip the Id fields in tables 2,3.
I want to do this in SSIS. My situation is a s follows.I have Supplier table and a table which has the supplier/product name and other details about the products. Both the table have a common column called SupplierName. Now I want to compare these two columns and if they are same then insert the ID from the Supplier Table into this second table where all are in one table.
Use Lookup transformation.
You can lookup Supplier table from Product table based on Supplier Name and select Supplier ID as output.
This will add SupplierID along with other columns of Product table to the data pipeline.