Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Convert Excel to SQL Design Query Expand / Collapse
Author
Message
Posted Tuesday, April 10, 2012 9:34 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 25, 2014 4:29 AM
Points: 119, Visits: 451
Hi,

We have an excel spread sheet that contains some basic data about daily incomes. Id like to bring it into SQL as they are constantly updating it just to allow it to used (new sheet for each month etc). Could anyone look over my theory and tell me if im going the right way. The dates area is a concern.

The excel spread sheet is made up :

Date | Site | budget | sales | profit/lose
----------------------------------------

Going the way of Codd, I think i need to break out Date to a new table? and Site.

So would have

DateTable:

DateID | FullDate | Month | FinYear
-----------------------------------

DateID = primary key, identity (1,1) - link to data table
FullDate = 10/04/2012 - date to link to
Month = 04 : April - for doing monthly calculations easily
FinYear = 2012/2013 - Fincial year is APril to April so wanted a way to work that out? I guess that should be a new table actually!?

SiteTable :

SiteID | SiteName

SiteID = primary key, identity (1,1) - link to data table
SiteName = Full Site Name

Data Table:
DateID | SiteID | budget | sales | profit/lose

DateID = link to full date details
SIteID = link to full Site Name
Budget = manual number
Sales = Manual number
Profit/Lose = Calculation to create % from budget and Sales



Does that sound about right?

With the date table? would you create a script to fill in all dates for 2 years or something? then update it every few years? or maybe create a SP to update it every month???


Views and corrections greatly received!


Thanks
Post #1280896
Posted Tuesday, April 10, 2012 4:02 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 4:06 AM
Points: 3,129, Visits: 3,252
Hi,
I had similar issue some months ago.
Your description is fine. There are always ways to realize something.
First.
I would like to comment about your DateTable and SiteTable
Why additional tables? You could just store a long-format of date in a column and then use the YEAR, MONTH, DAY … and the many other functions and options with them. In your queries you will have more frequently these functions, and it is not generally a problem.
In your way, by dividing the data into more tables, the update would be more complex rather than using just one table as your sheet is. I usually use to insert sheet’s data in a table with same order of fields. That showed as very practical to me, not only for cases like this one, but also in SSIS and/or DTS.
Second.
However, you could design a SSIS package to transform the data from your sheet and to insert it into a set of normalized tables.

How frequently do you need to update your sql table(s)? If once monthly then you’re all right, if weekly or daily, then you should develop an application.

Regards
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1281220
Posted Tuesday, April 10, 2012 5:22 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, December 23, 2014 7:18 PM
Points: 7,930, Visits: 9,654
It looks quite reasonable; presumably the data table is intended to have have (dateId,siteid) as primary key?
I would be inclined to use SQL date datatype, not any string like "28/10/2011", for fulldate; and make the Month and FinYear columns computed columns, not stored data, for example define month as
month = str(datepart(mm,fulldate),2)+': '+datename(mm,fulldate),
FinYear = datename(yy,dateadd(mm,-3,fulldate))+'/'+datename(yy,dateadd(mm,9,fulldate))
if those really are the formats you want.
Unless there is a very large number of rows, I would suggest not splitting out the date table - just have the full date instead of the dateid in the data table (the month and finyear columns don't use space if they are defined as computed columns); of course if you often search for a particular month or a particular financial year you might want to persist those columns so you could have indexes to make those searches efficient, and then they would take up space (both in the table itself and in those indexes), and in that case you might want to split out the date table - but even then those columns should ideally be persisted computed columns, not data entered by any other means, and rather than having an identity for the dateid column it might be sensible to make that a persisted compued column too, using something like dateid=1+datediff(dd,'1900-01-01',fulldate) ( that assumes you have no dates before 1900 - the constant date can be adjusted to fit if you do) if the number of rows in the data table is big enough to justify using a seperate dateid instead of the fulldate to save space in the data table at the expense of using extra space in the date table.


Tom
Post #1281257
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse