I have a table with 4 columns.
id is ai pk
jobno is fk from jobs table
qty
biditems_id is fk from biditems
there can be many jobno
there can be many biditems_id
but each row can only exist once, so a jobno cannot have 2 of the same biditems_id.
I want to create a cgridview to show different types of biditems as separate columns. so in the cgridview i will have jobno, qty, biditems_id as type 1, biditems_id as type 2 etc.
A jobno can have many biditems with a qty.
Related
So I'm generating a pivot table using pandas. I'm using index Location Name, Customer ID and Customer Name (SortName).
When I pivot it's returning a row for each Customer Name per CustomerID. You can see that all the customer names are zero except for the customer name actually associated with the ID. When I filter there isn't any data for the customerID with the other names. Why is it doing this? I really only want it to group for unique combinations of the 3 indexes that have data.
I figure this has to be easy, I'm just not sure how to ask the question.
I have thousands of records I imported from a Excel Spreadsheet in a Microsoft Access table with a field that I want to extract into a new table. How do I move the data from the field in the existing table to a new table and maintain the relationships to the record?
The goal is to move the existing data from the one field into a new table that will have a one-to-many relationship with the existing parent table.
For example, in a table called tblProperties I have the following fields:
Property_Address | Property_Owner | UtilityMeter_Number
I want to maintain a history of utility meters on properties as they are replaced, so I want to move the UtilityMeter_Number field from tblProperties into a new table called tblMeters and create a one-many relationship between the two so I can have multiple meter records for each property record.
How do I move all the existing data from the UtilityMeter_Number field in tblProperties into tblMeters, and maintain the relationship?
What is what I'm trying to do called, and how do I do it?
This is called normalizing data structure.
Use a SELECT DISTINCT query to create unique records. Use that dataset as source to create a new table. Something like:
SELECT DISTINCT CustID, LName, FName, MName INTO Customers FROM Orders;
Now delete unnecessary LName, FName, MName fields from Orders table.
Tables are related on the common CustID fields. An autonumber primary key is not utilized. If you do want a relationship on autonumber PK, then continue with following steps:
add an autonumber field in new table
create a number field in original table
run an UPDATE action SQL to populate new number field with autonumber value from new table - join tables on common CustID fields
also delete CustID field from original table
I have a scenario as described below need to create a SSIS Package for that.
I have 3 COLUMNS in source table which needs to be entered in destination table.
But all these columns has to be looked up in the look up table of destination database and then enter their ID's in the destination column.
For example
Source table has 3 columns with values
idnum static type timedimension geography modified date
1 price daydate france 8/12/2015
2 RetailpRICE WEEK ITALY 9/12/2014
I want a package which looks up the column values with the matchin ID and populates in the destination table...
I know we can use the LOOKUP transform to update the data for one single column in destination table what about the other columns which I need to insert along with the lookup insertion.
How can I achieve this ? Also is there a way to pull only the recent data from the source table using modified date column values
Use a different lookup for each lookup table that you need to reference to get the Ids. So if each of your columns that you want IDs for gets its ID from a different table, then you need to use three lookups, one after the other, until you have all three IDs.
I am currently working on a database where I am trying to find all the transactional type tables (where the table name does not start with _Result or _ History) in the database and then display how many times each table is used in a calculation for the database model.
The purpose of finding out this is to determine the most important tables in the calculation, so that these certain tables will have a priority when updating statistics.
There are currently two tables I am working with.
1) The first table called tmpCalcSources shows the name for all the source tables in the database (Column called 'Source') along with the Calculation ID (Column called 'CalculationID') associated with it
2) The second table called tmpCalcSourceRows shows the source table name (Column called 'TableName') as well as the amount of rows associated with each source table (Column called 'RowNum')
I currently have this query:
SELECT Source,
COUNT(CalculationID) AS NumberOfUses
FROM tmpCalcSources
WHERE Source not like '%_Result%'
GROUP BY Source
ORDER BY NumberOfUses DESC;
The above query provides me with the following table:
plPeriods 292
plMeasures 10
Time 43
etc...
I am now trying to add one more thing to the above table. I want it to also show the number of rows contained in each table (so a another column). I would like to take the column 'RowNum' from tmpCalcSourceRows table and be able to display that in the table shown above.
Is this what you're looking for:
select
Source
, NumberOfUses
, numberofrows
from (
SELECT Source,COUNT(CalculationID) AS NumberOfUses
FROM tmpCalcSources
WHERE Source not like '%_Result%'
GROUP BY Source
) tableUses
join numRowsTable on numRowsTable.TableName=tableUses.Source
ORDER BY NumberOfUses DESC;
Consider my data as inventory list separated by categories.
When I started I had one table that should have been split into two tables, else in the oldTable the columns in a given row would have been un-related. I have created two new tables in my database, one for categories and the other for data/items. Now I am trying to use the oldTable existing data to fill the newTable data/items table so I can learn SQL and not have to manually do it. The categories table I filled in manually because I could not see how to do it otherwise.
The old table has:
tableName (
id,
categoryA,
categoryB,
categoryC,
categoryD,
categoryE,
categoryF,
isPriorityA,
isPriorityB,
isPriorityC,
isPriorityD,
isPriorityE,
isPriorityE
)
The new tables have:
Categories (
cat_id,
name
)
dataItem (
item_id,
cat_id,
name,
priority,
description,
URL
)
How do I force the new dataItem table to require the cat_id match one of the values in the Categories.cat_id table column? Perhaps to give an error if a value is added outside of the range? I believe this may be mapping or linking tables, to thereby make them relationship tables.
How do I copy the tableName data to the dataItem table one column at a time in alphabetical order bringing the name,priority with it and allowing it to auto-increment the item_id value?
Sounds like you want to use a foreign key to limit dataItem.cat_id to values in Categories.cat_Id. Something like this:
ALTER TABLE dataItem ADD FOREIGN KEY (cat_id) REFERENCES Categories(cat_id);
Exact syntax may depend on which database you are using. For more info on foreign keys see: http://www.w3schools.com/sql/sql_foreignkey.asp