Thursday, April 26, 2007

Buy me a Pink Cadillac

Today is my last day at Ariamedia. I was recently offered a position developing software for Mary Kay, and I will start on April 30.

It's been a tough decision to leave. I enjoyed working at Ariamedia, and met a lot of awesome, very talented individuals. I'm sure I'll be hearing about all of them in the future. My team has been on a push to get the software development lifecycle more agile (Scrum specifically), and I'm very glad to have been a part of that. I was also a big part of getting our source control moved to Subversion. I'm definitely glad I was involved with that - I'll never go back to SourceUnSafe and now, I don't have to.

Choosing Mary Kay was a big decision for me. I've never worked in a corporate environment. I've never had to wear a tie to work. So, that will be interesting.

I'll be glad to be working with a good friend of mine, as well.

I also had another very enticing offer that, while I didn't accept, I was very flattered to have received, and I'm glad to know that avenue is open to me. However, after looking at the choices that I had, and where I'm at in life, I'm happy with my decision.

Leaving a job is difficult. I've made friends, learned new things, and done a lot of (I hope) good work. You always leave with projects unfinished, but I know that I'm leaving them in very capable hands.

So long, and thanks for all the fish.

Tuesday, April 17, 2007

Automatically insert SortOrder value in SQL

So, the other day I ran into an interesting problem. I've been using CodeSmith and .netTiers to develop all that "boring business/data access code" for an application at work. One of our requirements was to have a list of things with a user-specified sort order.

So, I added a SortOrder column to the table (not sort_order, but more on that later), and ran my code-gen. I didn't want to put the "automatic sort order insertion" into a stored procedure (since they're all generated), but I also didn't want to have to hit the database several times just to figure out what the next value should be.

Then someone showed me that you can have a function for a default value in a column in SQL Server. I knew this instinctively (NEWID() for a uniqueidentifier, or GETDATE() for a "date inserted" column) but I hadn't thought about using my own function.

So, here it is:

DECLARE @newMax int

SELECT @newMax = MAX(SortOrder) + 1 FROM TableWithSortColumn WHERE SomeForeignKeyId = (SELECT SomeForiegnKeyId FROM TableWithSortColumn WHERE Id = (SELECT IDENT_CURRENT('TableWithSortColumn')))

RETURN @newMax

I just created the function, set my default value for the sort column to dbo.GetNewSortOrder() and

Disclaimer: I'm not particularly sure this is really the right place to do this type of thing. If anyone has any suggestions or comments, please let me know. If you think this is a terrible idea and will cause my application to start fires and kidnap small children - definitely let me know. I'd like to avoid any legal entanglements.