Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I am working on a Sales Order Confirmation ASP.net application (Sql Server 2000). In this application there is an Excel file that has to be uploaded every month that contains the Sales FORECAST given by all our Customers for the next 12 months.

 

It has the following format (these will be the columns of the excel sheet)

CustomerId

ProductID

Year

Jan

Feb

March

April

...

...

Dec

 

In the JAN to DEC columns the Customer specifies its forecast for that month.

 

I would like to know the best Database structure that I should use for importing this excel file. The easiest way would be

 

create a table with a structure similar to the excel file, but what I will require later will be a lot of Queries that would

 

group on ProductID and Customer ID. Reports like the Customer's FORECAST vs Actual Orders per month, trend for a Product for

 

the past 3 months etc.

 

I would like your suggestion on the IDEAL Table structure to use and how to IMPORT the Excel file into that table structure.

 

My idea was something like this

 

Master Forecast Table

---------------------

ID

CustomerID

ProductID

 

Detail Forecast Table

---------------------

ID (foreign Key)

Month

Year

ForeCastQuantity

 

 

Thus each row from the Excel File, will have 12 rows (jan to dec) in the Detail Forecast Table.

 

Am I on the right track ?????

 

 

If this OK, what is the best way to convert the Excel file into this format???

When you gotta go,you gotta go !!!!!!!
Posted

Just a quickie...

Why two tables? The only reason for the first table would be to create a unique key to use in the second, right?

Why not...

Forecast Table

---------------------

CustomerID

ProductID

Month

Year

ForeCastQuantity

 

/Kejpa

Posted (edited)
Just a quickie...

Why two tables? The only reason for the first table would be to create a unique key to use in the second, right?

Why not...

Forecast Table

---------------------

CustomerID

ProductID

Month

Year

ForeCastQuantity

 

/Kejpa

First, save yourself alot of trouble and make Month, Year one fields. . . a Date. You can force it to be the first day of the month, or the last, depending on what is appropriate. Dates are dates! treat them that way!

 

Second I could see a need for two tables. . . if there is anywhere else in the database where (CustomerID, ProductID) is a primary key, it makes sense to add a surrogate to that table and then use that surrogate key in the MonthlyForecast for that relationship. for example, lets say you also were trackingproduct inquiries such as Customer A requested info on Product 1 and you were keeping track of Customer support for a customer and Products such as JohnDoe supports Customer A on Product1 and MaryDoe supports Customer A on product 2. this would be the best schema:

note: Bold indicates primary key fields, Italic indicates surrogate key

 

[CustomerProduct]

CustomerID references (Customer)

ProductId references (Product)

CustomerProductID (unique)

 

[ProductInquiry]

CustomerProductID references (CustomerProduct)

DateOfInquiry

DateOfResponse

 

[ProductSupport]

CustomerProductID references (CustomerProduct)

EmployeeID references (Employee)

 

[SalesForecast]

CustomerProductID references (CustomerProduct)

ForecastDate

ForecastQuantity

 

Third, as far as unpivoting an excel spreadsheet I don't know of any automatic way.

 

you can open the spreadsheet using the Jet OleDb Provider.

 

psuedo code:

for i = 0 to 11

select CustomerID, ProductID, i Month, monthcolYear into aDataTable

 

 

add a ForecastDate column to aDataTable as a date time and iterate throught the table setting the ForecastDate based on Month and Year

 

now you got a datatable you can use to move to the SQL server

 

psuedo code:

foreach row in aDataTable

if not exist

select * from CustomerProduct

where CustomerProduct.CustomerID = aDataTable.CustomerID and

CustomerProduct.ProductID = aDataTable.ProductID

insert into CustomerProduct(CustomerID, ProductID)

values(aDataTable.CustomerID, aDataTable.ProductID)

 

foreach row in aDataTable

insert into SalesForecast

select CustomerProductID, aDataTable.ForecastDate,

aDataTable.ForecastQuanity

from CustomerProduct

where CustomerProduct.CustomerID = aDataTable.CustomerID and

CustomerProduct.ProductID = aDataTable.ProductID

Edited by Joe Mamma

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...