Saturday, March 24, 2012

Working with multiple table column headers

Is there an easy way to work with a table that has multiple column headers? ie. as an example I have two column headers that in the next row are then broken down into a further two column headers each (thus 4 columns of data in total). This table is currently in excel but I want to import it into a SQL database (unless there is a better option). It doesn't appear that thsi can be done, or can it?

Thanks in advance.

Robert

Four columns. Headers do not equate to columns, they're merely display functionality. For example, you have a spreadsheet that shows opening and closing prices (columns) for a stock (the row) for each day of the month (31 "headers" that span two columns each). The relevent entity is a stock, and it has an opening price and a closing price for a specific date.

The spreadsheet would show 62 columns, two for each day of the month. The database has four columns, a stock name, an opening price, a closing price and a date. From those four columns a query can extract the data and display it as you did in the spreadsheet. Toss in a unique ID column and you pretty much cover everything you need to display that table, or a weekly version, or an annual version with opening and closing prices for each month, or even a graph of opening and closing prices of all the stocks in your portfolio over the last six months.

That's the beauty of a database. And that's why you need to learn database design techniques and entity relationships. Before you design the database for your application.

Jeff

0 comments:

Post a Comment