harriyott.com

Wednesday, February 27, 2008

Pulling data from Excel

I spent much of today pulling data from Excel to put into SQL Server tables. The data was pretty well formatted, but each row of spreadsheet data traverses many database tables.

I saved the spreadsheet to CSV, and then used my trusty friend, the world's simplest code generator (javascript edition), to generate SQL statements from the many rows of CSV which I pasted into SQL Manager, e.g.

INSERT INTO People (FirstName, LastName) VALUES ('$2', '$3')

Some of them became quite convoluted, as once I'd inserted rows into the People table, I had to look up the IDs for the link tables. Also, there were a couple of Irish names with apostrophes in them, so I used a regular expression to double them up:

~(:Wh)'~([,|:Wh]|\))

n.b. I think this is a Visual Studio style regex, as it seems a little different to what I vaguely remember (not that I do remember, that is).

Tip - using units of measure

When naming a variable or database column that is used to store a measure, include the units of measure in the name. For example, instead of calling a column Height, call it HeightInInches. This prevents misunderstandings in future maintenance.

Friday, February 22, 2008

Lines of code != running time

I've just realised I do a bizarre thing in my subconscious when I'm coding. Now I'm all .NET 3.5, I've been writing code like:

feeds.ForEach(f => ProcessFeed(f));

One line of code instead of the usual four (OK, so two lines were the curly brackets) to write a foreach loop.

Now the thing is, I've unwittingly felt like the code now runs faster because the method is shorter. Of course that isn't true, but having nicer, shorter, eleganter, maintainabler code feels like it should be more efficient too.

Friday, February 01, 2008

Microsoft to buy Yahoo!?

I've been using flickr, upcoming and del.icio.us since before they were bought by Yahoo, and I was a little nervous about them all joining my Yahoo profile. Am I going to have to sign into these with my Microsoft Live account now?