(Revised)Database Design Question, Header With Two Detail.. Pls Help
Jul 20, 2005
Hi All,
There is some additional info I forget on this same topic I just posted.
I have a database design question, pls give me some help..
I want to define tables for salesman's sales target commission . The
commission could be given per EITHER sales amount of : Group of Products OR
Group of Brand. e.g : the data example :
For one salesman_A :
product_1, product_2, product_3 etc.. => sales = $100 - $200 =>
commission = 5%
product_1, product_2, product_3 etc.. => sales = $201 - $400 =>
commission = 10%
Brand_A, Brand_B, Brand_C .. etc => sales = $100 - $200 =>
commission = 2.5%
Brand_A, Brand_B, Brand_C .. etc => sales = $201 - $400 =>
commission = 5%
Below is my table design, is this a good design or something is wrong here ?
Thank you for your help.
CREATE TABLE Sales_Commission_Header (
Sales_ID Char(4) ,
Sales_Commission_Group Char(4),
Note Varchar(30),
Constraint Sales_Commission_Header_PK Primary Key(Sales_ID,
Sales_Commission_Group)
)
Alter Table Sales_Commission_Header Add Constraint
FK_Sales_Commission_Header Foreign Key (Sales_Commission_Group)
References Commission_Group_Header(Sales_Commission_Group)
CREATE TABLE Sales_Commission_Detail (
Sales_ID Char(4) ,
Sales_Commission_Group Char(4),
Sales_From Decimal(12,2) ,
Sales_To Decimal(12,2) ,
Commission Decimal(5,2),
Constraint Sales_Commission_Detail_PK Primary Key(Sales_ID,
Sales_Commission_Group, Sales_From, Sales_To)
)
Alter Table Sales_Commission_Detail Add Constraint FK_Sales_Commission
Foreign Key (Sales_ID, Sales_Commission_Group) References
Sales_Commission_Header(Sales_ID, Sales_Commission_Group)
--------------------------------------------
** ALTERNATIVE _1 :
CREATE TABLE Commission_Group_Header (
Sales_Commission_Group Char(4) Primary Key,
Note Varchar(30)
)
CREATE TABLE Commission_Group_Detail_Product (
Sales_Commission_Group Char(4),
Product_ID VarChar(10), -- This product_ID will be FK
reference to master product
Constraint Commission_Group_Detail_Product_PK Primary
Key(Sales_Commission_Group, Product_ID)
)
Alter Table Commission_Group_Detail_Product Add Constraint
FK_Commission_Group_Detail_Product Foreign Key (Sales_Commission_Group)
References Commission_Group_Header(Sales_Commission_Group)
CREATE TABLE Commission_Group_Detail_Brand (
Sales_Commission_Group Char(4),
Brand_ID VarChar(10), -- This brand_ID will be FK
reference to master brand
Constraint Commission_Group_Detail_Brand_PK Primary
Key(Sales_Commission_Group, Brand_ID)
)
Alter Table Commission_Group_Detail_Brand Add Constraint
FK_Commission_Group_Detail_Brans Foreign Key (Sales_Commission_Group)
References Commission_Group_Header(Sales_Commission_Group)
** ALTERNATIVE _2 :
CREATE TABLE Commission_Group_Header (
Sales_Commission_Group Char(4),
Group_Type Char(1), -- 'B': Brand Group 'P': Product Group
Note Varchar(30),
Constraint Commission_Group_Header_PK Primary Key(Sales_Commission_Group,
Group_Type)
)
CREATE TABLE Commission_Group_Detail (
Sales_Commission_Group Char(4),
Group_Type Char(1), -- 'B': Brand Group 'P': Product Group
Product_Brand_ID VarChar(10),
Constraint Commission_Group_Detail_PK Primary Key(Sales_Commission_Group,
Group_Type, Product_Brand_ID)
)
Alter Table Commission_Group_Detail Add Constraint
FK_Commission_Group_Detail Foreign Key (Sales_Commission_Group)
References Commission_Group_Header(Sales_Commission_Group, Group_Type)
The PROBLEM here is : with Product_Brand_ID , I CAN NOT make foreign key
into both Master Product and Master Brand.
So which one is better design ?
split the Commission_Group_Detail into Two tables, product and brand , and
make the FOREIGN KEY
to master product and master brand (previous mail)
OR
combile Commission_Group_Detail for Product and Brand into one table like
above
and NOT make any FK to master Product or Brand ?
Thank you for your help,
Tristant
View 1 Replies
ADVERTISEMENT
Apr 16, 2004
I am creating a DTS package to export a text file. My question is: does anyone have any ideas on how for one read of the tables I can produce 2 lines of output. Here is how the file layout needs to be...
HEADER
DETAIL
HEADER
DETAIL
HEADER
DETAIL
I am a little confused about how I can stagger header and detail using the same data.
I appreciate any help you can give. Hopefully my explanation of the problem is understandable.
Thanks, Val
View 2 Replies
View Related
Mar 29, 2007
Hi,
I'm new to SSRS. I was just wondering how do I make the header for a detail record appear once per grouping rather than once per detail record?
Thanks.
View 1 Replies
View Related
Jun 4, 2004
Im trying to copy details from a specific header as details of a different header (eg. all sales items from invoice #10 copied as sales items of invoice #11).
So far I have two stored procedures:
1) sp_copyDetailsOne
/*Create a recordset of the desired items to be copied*/
CREATE PROCEDURE sp_copyDetailsOne @invoiceIdFrom INT, @outCrsr CURSOR VARYING OUTPUT AS
SELECT itemId, itemPrice, itemDescription, itemQuantity
FROM tblSalesItems
WHERE (invoiceId = @invoiceIdFrom)
OPEN @outCrsr
2) sp_copyDetailsTwo
CREATE PROCEDURE sp_copyDetailsTwo @invoiceIdFrom INT, @invoiceIdTo INT
/*Allocate a cursor variable*/
DECLARE @crsrVar CURSOR
/*Execute sp_copyDetailsOne to instantiate @crsrVar*/
EXEC sp_copyDetailsOne @invoiceIdFrom, @outCrsr = @crsrVar OUTPUT
/*Loop through the recordset and insert a new record using the new invoiceId*/
FETCH NEXT FROM @crsrVar
WHILE @@FETCH_STATUS = 0
BEGIN
/*Run the insert here*/
INSERT INTO tblSalesItems
(invoiceId, itemId, itemPrice, itemDescription, itemQuantity)
VALUES (@invoiceIdTo , 5, $25.00, N'Black T-Shirt', 30)
/*Fetch next record from cursor*/
FETCH NEXT FROM @crsrVar
END
CLOSE @crsrVar
DEALLOCATE @crsrVar
My question comes on the Insert of sp_copyDetailsTwo, as you can see the values are hard coded and I want them pulled from the cursor. However I don't know how to do this - do I need varables or can I access the cursor values directly in my VALUES clause? Or is this whole approach needing overhauled. Any advice is welcome.
Thanks
View 2 Replies
View Related
Feb 19, 2008
Hi Anyone
How to export a header and details data from two different table and export it in the below format ?
RecordCount = 129 ------------> Header
001|Manager|2399.00|12 ------------> Detail Lines
002|Technican|1800.00|15
003|Mechanic|1500.00|18
.......
Total Amount = 180000.00 ------------> Footer Line
I want to use the SSIS to do this job can anyone explain step by step.
Thanks,
Madhu
View 3 Replies
View Related
Sep 16, 2014
I have a flat file I need to generate, wanted to create my file from a SQL view.
Is there a way to have a Header and Detail Record for each Record in my view?
Fields would be:
Line no type period ref amt date Inv_no
0 M 1 3/3/2014
1 M Pay inv: 400.00 12345
where 0 is the header and 1 is the detail. Only certain fields will be in the header and others in the detail.
View 1 Replies
View Related
Feb 5, 2008
Hello,
I have a header and detail table. I want to create a constraint on the detail table, based on a value it's linked to in the header table. If the bit is checked in header then a unique value is required , if it's not checked then a NULL value is acceptable.
Many thanks in advance.
View 3 Replies
View Related
Feb 21, 2007
I can't believe it's been a few days and I can't figure this out. We have a flat file (purchaseOrder.txt) that has header and detail lines. It gets dropped in a folder. I need to pick it up and insert it into normalized tables and/or transform it into another file structure or .NET class.
10001,2005/01/01,some more data
SOME PRODUCT 1, 10
SOME PRODUCT 2, 5
Can somebody place give me some guidance on how to do this in SSIS?
View 2 Replies
View Related
Sep 13, 2007
I have a flat file with header and detail information, it is actually employee punch card data. I need to parse the header line which contains the Employee ID and don't save it to a table just save the value. Then with the detail line, parse the different data elements and save them along with the employee ID to one table. Then continue until the next header line is read.
The file looks something like this:
FINNEY,RONNIE 0001005420
Mon 09/03 700a HOL 8.00
Tue 09/04 630a*E 326p 8.50 8.50
Wed 09/05 645a 330p 8.00 16.50
Thu 09/06 639a 2.40 18.90
HALL,MARK 0001005601
Mon 09/03 700a HOL 8.00
Tue 09/04 608a*E 257p 8.40 8.40
Wed 09/05 601a*E 259p 8.50 16.90
Thu 09/06 606a*E 3.30 20.20
JONES,WILLA JEAN 0001005702
Mon 09/03 700a HOL 8.00
Tue 09/04 556a*E 326p 9.10 9.10
Wed 09/05 600a*E 328p 9.00 18.10
Thu 09/06 554a*E 3.50 21.60
So I think I need a data flow transformation object that let's me save the Employee ID into a variable available when the next record is read. What type of transformation would be best?
View 1 Replies
View Related
Nov 23, 2015
I have a report with two groups and a detail row (subtotals & totals to follow). When I add the child (detail row) it pushes out to the right of the parent column. Is there any way to start the detail row all the way back to the left hand side of the page? I lose a lot or real estate with the group descriptions.
View 5 Replies
View Related
Mar 16, 2006
I€™ve created with the help of some great people an SSIS 2005 package which does the follow so far:
1) Takes an incoming txt file. Example txt file: http://www.webfound.net/split.txt
The txt file going from top to bottom is sort of grouped like this
Header Row (designated by €˜HD€™)
Corresponding Detail Rows for the Header Row
€¦..
Next Header Row
Corresponding Detail Rows
€¦and so on
http://www.webfound.net/rows.jpg
2) Header Rows are split into one table, Maintenance Detail Rows into another, and Payment Detail Rows into a third table. A uniqueID has been created for each header and it€™s related detail rows to form a PK/FK relationship as there was non prior to the import, only the relation was in order of header / related rows below it when we first started. The reason I split this out is so I can massage it later with stored proc filters, whatever€¦
Now I€™m trying to somehow bring back the data in those table together like it was initially using a query so that I can cut out each of the Header / Detail Row sections into their own txt file. So, if you look at the original txt file, each new header and it€™s related detail rows (example of a cut piece would be http://www.webfound.net/rows.jpg) need to be cut out and put into their own separate txt file.
This is where I€™m stuck. How to create a query to combine it all back into an OLE DB Souce component, then somehow read that souce and split out the sections into their own individual txt files.
The filenames of the txt files will vary and be based on one of the column values already in the header table.
Here is a print screen of my package so far:
http://www.webfound.net/tasks.jpg
http://www.webfound.net/Import_MaintenanceFile_Task_components.jpg
http://www.webfound.net/DataFlow_Task_components.jpg
Let me know if you need more info. Examples of the actual data in the tables are here:
http://www.webfound.net/mnt_headerRows.txt
http://www.webfound.net/mnt_MaintenanceRows.txt
http://www.webfound.net/mnt_PaymentRows.txt
Here's a print screen of the table schema:
http://www.webfound.net/schema.jpg
View 17 Replies
View Related
Jun 2, 2015
I need to insert data into Header & Detail table. As shown in the below xml,
RecordID is identity-column and incremented by 1, after new record is saved into Header table. Need to assign the same recordID for the detail also.
Expecting output should be like as shown below:
How can we accomplish this requirement.
View 8 Replies
View Related
Sep 5, 2015
I have a report with 3 groups, and a toggle on the first cell in the group header, and group totals on that line also. So it renders as:
- Group 1 G1Total G1Total G1Total
- Group 2 G2Total G2Total G2Total
- Group 3 G3Total G3Total G3Total
Detail DAmt DAmt DAmt
I would like to save some space and render more like
- Group 1 G1Total G1Total G1Total
- Group 2 G2Total G2Total G2Total
- Group 3 G3Total G3Total G3Total
Detail DAmt DAmt DAmt
I haven't been able to find a way to have the first group cells overlap each other. Is there a way to do that and am I missing something obvious?
View 4 Replies
View Related
Nov 21, 2007
I have a need to show a row inside a table group to simulate a header row for the data rows inside the group. The table will not have a real header or footer. Thanks for the help.
View 1 Replies
View Related
Nov 19, 2007
Hi,
AM in need of SSRS 2005 design documents for a project purpose. Can somebody let me know where can i find these documents? Thanks in advance
View 1 Replies
View Related
Sep 24, 2007
Report needs to display as follows
Parent
col1,col2,col3...
val1,val2,val3
expandable section
child1
colA,colB,colC
valA,valB,valC
child2
colA...
....
repeat
Am currently implementing this as nested list controls with textboxes due to the fact that the headers for the parent and child differ. (By header I mean the column labels)
1. is there a better way of doing this as I much prefer working with tables/matrix controls?
2. how can I stop the header from scrolling - this is possible with tab/mtx controls. The alternative is to repeat the headers all down the page which wastes space and looks messy
3. How can I apply 'interactive sorting' to the parent columns?
Thanks
View 1 Replies
View Related
Sep 14, 2007
I am listing detail transaction lines in a table sorted by account and order number.
the problem is that I only want to see the detail if the sum of a value field is zero for all the transactions in an order otherwise ignore the detail for that order.
I was trying Group by and Having but this doesn't seem to do what I need.
Being relatively new to Reporting services, any nudge in the right direction would be useful.
View 4 Replies
View Related
May 16, 2008
I need to compare our late sales orders to our late purchase orders. The query for the sales orders would be this:
SELECT S1.*,
S2.*,
S3.*
FROM somast S1
INNER JOIN soitem S2
ON S1.fsono = S2.fsono
INNER JOIN sorels S3
ON S2.fsono + S2.finumber = S3.fsono + S3.finumber
The PO table query is like this:
SELECT P1.*,
P2.*
FROM pomast P1
INNER JOIN poitem P2
ON P1.fpono = P2.fpono
WHERE NOT(P2.fmultirls = 'Y')
AND P2.frelsno = 0
somast is the sales order master table, soitem is the items table, and sorels is the release. pomast is the Purchase Order Master and poitem is the purchase order items table. I don't intend to leave the *'s and will clean up the query afterwards with the specific fields I need.
The poitem table as a field called fsokey which contains the sales order number if the PO and the SO are related.
So, here is my question. I want all the sales orders and only the purchase order information pulled for which the fsokey corresponds. Would I do this with a subquery or is there some very complex (for me) inner and outer join query that I would use.
I greatly appreciate some help with this.
View 3 Replies
View Related
Apr 14, 2007
I have windows application (Basically a accounting system). I want to use either SQL authenticaion, or Windows authentication for my users of the application (Basically each db user will have their own account in Users for that db, so I can have sql control the access).
All access to the db is via stored procedures, but I want to have a set schema for each user type:
Supervisor
Manager
Data Entry
etc.
All with a predefined access to the proper stored procedures(So far fairly simple).
In addition to this I want to be able to set the specifics of that user in my .net application via a interface (so a user by default will have the pre-defined schema, when a supervisor opens this interface, they can add/remove access to other stored procedures)
Here's the issue. Is this the proper methodology to achieve this, because it's quite of bit of programming work. I don't want to do it then need to re-due everything.
Also should I use Windows Authentication, or SQL, or have a completly seperate table in the DB where I do manual authentication then have the .net application restrict the access?
Any help or comments on this approach will be helpful. Also ifanyone has found any articles or information similiar to what I am trying to accomplish, please point me in the correct direction.
Thanks.
View 8 Replies
View Related
Feb 11, 2004
Ok here's a big one.
First I'm a big NEWBIE, so it'd be great if you can provide a little explanation as to how this should be done...
Here's what I want to do, but have no idea how to approach it.
I have a table with Quotes (table Quote) in them (for a Sale's Team). Each has a quote number (qtQN) and this number is sequencial but sometimes revised where a letter is added at the end. Like so:
qtQN__________Date
---------------------------
111q0001--------02/01/04
111q0002--------02/02/04
111q0002A------02/03/04
111q0002B -----02/04/04
222q0005--------01/15/04
etc... ------------- etc...
The first 3 digit are company codes and pretty unimportant to this problem. As you can see, 111q0002 has three versions. A, B, and no letter. The most up to date is B. So in this list I want to list only the most up to date quotes. So the resulting list would be:
111q0001
111q0002B
222q0005
Get it? Good, cuz I have no idea how to query that... any help at all is appreciated!
I'm using MS SQL Server 2k and scripting with ASP 3.0
View 6 Replies
View Related
May 30, 2000
Hi,
I want to write a sp with structure:
PROCEDURE TEST
@dbname1 varchar(25)
@dbname2 varchar(25)
AS
1. change current database to another, example for DB1 database
2. execute commands or block commands in DB1
3. change current database to another, example for DB2 database
4. execute commands or block commands in DB2
...
Can I do that? Who can help me? Thanks.
qhbaby@hotmail.com
View 1 Replies
View Related
May 13, 2015
I have a scenario like below
Product1
Product2 Product3
Product4 Product5
Product1 1
1 0 0
1
Product2 1
1 0 0
1
Product3 0
0 1 1
0
Product4 0
0 1 1
0
Product5 1
1 0 0
1
How to design tables in SQL Server for the above.
View 2 Replies
View Related
Mar 25, 2008
Hello,
I'm new to SQL and need help with a query. Not sure if this is the right place.
I have 2 tables, one MASTER and one DETAIL.
The MASTER table has a masterID, name and the DETAIL table has a detailID, masterID, and value columns.
I want to return a populated MASTER table with entries based on the DETAIL.value.
SELECT MASTER.*
FROM MASTER
WHERE DETAIL.value > 3
This is a simplified version of my problem. I can't figure out how to set the relationship between MASTER.masterID and DETAIL.masterID. If I do an INNER JOIN, the number of results are based on the number of DETAIL entries. I only want one entry per MASTER entry.
Hope this makes sense.
How can I do this?
GrkEngineer
View 9 Replies
View Related
Feb 13, 2002
Ok, I'm doing a football database for fixtures and stuff. The problem I am having is that in a fixture, there is both a home, and an away team. The tables as a result are something like this:
-------
Fixture
-------
fix_id
fix_date
fix_played
----
Team
----
tem_id
tem_name
-----------
TeamFixture
-----------
fix_id
tem_id
homeorawayteam
goals
It's not exactly like that, but you get the point. The question is, can I do a fixture query which results in one record per fixture, showing both teams details. The first in a hometeam field and the second in an away team field.
Fixture contains the details about the fixture like date and fixture id and has it been played
Team contains team info like team id, name, associated graphic
TeamFixture is the table which links the fixture to it's home and away team.
TeamFixture exists to prevent a many to many type relationship.
Make sense? Sorry if this turns out to be really easy, just can't get my head around it at the mo!
View 2 Replies
View Related
Mar 13, 2008
I need some help. I am writing a report in SSRS 2005 that I then need to export to Excel. When I put a report header I would expect the header to not display in the Excel spreadsheet until the Print Preview or the Print. The report footer works just fine I put some text in the footer, and it shows up in the footer. The header though, shows up as a row in the Excel spreadsheet that then causes columns to merge. How do I get the report header to act like a page header?
View 1 Replies
View Related
May 13, 2015
I am making a book-like report, I am using a report that has a header and calling a sub-report that has it's own header. However the sub-report header is not showing on the parent report. Parent report header is prevailing over the sub-report. Is it possible to have both headers displaying?
View 3 Replies
View Related
Nov 6, 2007
I have a report that I created and the report was working until I added some fields to a group footer row in a table.
My table has 5 group levels. I had information displaying in the 5th level header group and detail. It was working fine. Then I added some fields to the 4th level group footer. Now it displays only the Page header, Table header, and the 4th level group footer data.
What happened to the rest of the data?
All the cells and rows I want to display have the Visibility Hidden set to false. I tried removing the objects I added (to the 4th level group footer) and it still does not work. Is this a bug or did I set something that is hiding the data.
Thanks,
Fred
View 1 Replies
View Related
Nov 6, 2007
Hi Friends,
There is a one header in the report, when I publish and hit the report in IE(internet explor) the header appears fine on first page when I go to next page this header does not appear.
But in mozilla the header is visible on every page of the report. so it is working fine in mozilla.
I donot why it is happening?
Your help is highly appreciated.
Thanks
Novin
View 1 Replies
View Related
Jan 23, 2007
How to display an database image in the Report page header of sql server reporting service?
View 3 Replies
View Related
Oct 29, 2015
I actually work in an organisation and we have to find a solution about the data consistancy in the database. our partners use to send details to the organisation and inserted directly in the database, so we want to create a new database as a buffer database to insert informations from the partners then make an update to the main database. is there a better solution instead of that?
View 6 Replies
View Related
Feb 24, 2006
Hello everyone,I have a webcontrol that uses database-structures alot, it uses the system tables in SQL to read column information from tables. To ease the load of the SQL server I have a property that stores this information in a cache and everything works fine.I am doing some research to find if there are anyway to get information from the SQL server that the structure from a table has changed.I want to know if a column or table has changed any values, like datatype, name, properties, etc.Any suggestions out there ?!
View 3 Replies
View Related
Jul 23, 2005
I have a system that basically stores a database within a database (I'msure lots have you have done this before in some form or another).At the end of the day, I'm storing the actual data generically in acolumn of type nvarchar(4000), but I want to add support for unlimitedtext. I want to do this in a smart fashion. Right now I am leaningtowards putting 2 nullable Value fields:ValueLong ntext nullableValueShort nvarchar(4000) nullableand dynamically storing the info in one or the other depending on thesize. ASP.NET does this exact very thing in it's Session State model;look at the ASPStateTempSessions table. This table has both aSessionItemShort of type varbinary (7000) and a SessionItemLong of typeImage.My question is, is it better to user varbinary (7000) and Image? I'mthinking maybe I should go down this path, simply because ASP.NET does,but I don't really know why. Does anyone know what would be the benifitof using varbinary and Image datatypes? If it's just to allow saving ofbinary data, then I don't really need that right now (and I don't thinkASP.NET does either). Are there any other reasons?thanks,dave
View 7 Replies
View Related
Aug 16, 2007
Hi All,Can u please suggest me some books for relational database design ordatabase modelling(Knowledgeable yet simple) i.e. from which we couldlearn database relationships(one to many,many to oneetc.....),building ER diagrams,proper usage of ER diagrams in ourdatabase(Primary key foreign key relations),designing smallmodules,relating tables and everything that relates about databasedesign....Coz I think database design is the crucial part of databaseand we must know the design part very first before starting up withdatabases.....Thanks and very grateful to all of you....Vikas
View 3 Replies
View Related