SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Convert Excel to SQL Design Query


Convert Excel to SQL Design Query

Author
Message
n00bDBA
n00bDBA
SSC Veteran
SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)SSC Veteran (266 reputation)

Group: General Forum Members
Points: 266 Visits: 467
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
Igor Micev
Igor Micev
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5888 Visits: 5080
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
My blog: www.igormicev.com
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14270 Visits: 12197
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search