What the Heck, Worth a Shot

I’m posting to get another entry in Chris Pirillo’s contest. If I win, I might give a few LEGO kits to my nieces, but the rest will go to local Oshkosh charities. There are so many families in this town that could use a few nice toys. Twitter once found me a job, maybe mattmutz.com can get a package from Santa to some local families that are less fortunate than mine. There are many in this town that could use a hand.

Leave a Comment

SQL Server Derived Tables: What they Are, and Why You Want to Know about Them

Today I was given the chance to complain that stored procedures are called stored procedures. I’ve never liked that name. I’d much prefer they had been named “compiled queries” because that’s what they are. This led to me having the chance to say that derived tables should have been called “named queries” because that’s what they are.

What’s a derived table? Think of it as a query with a name (hence “named queries”).

I’m not going to build tables and data to illustrate and compare why they are often so much faster than temp tables. Thus I have no schema to compare this example against, and I apologize if I miss something silly and give you an example that doesn’t work. If that happens, just comment on this post and I’ll fix it.

Here’s the set-up: I want to send a mailing to all customers who have purchased in the last 90 days. I will use my customer table and my order table. (My customers have only one address — this post does not attempt to get into the problem of many addresses per customer.)

I’ve seen this done frequently like this:

––create proc stuff deleted for brevity
select distinct CustomerNumber into #RecentOrders from Orders where OrderDate >= DATEADD(dd, -90, GETDATE())

select CustomerName, CustomerAddress, CustomerCity, CustomerState, CustomerZIP
from Customer
inner join #RecentOrders ro
on ro.CustomerNumber = #RecentOrders.CustomerNumber
––end of temp table example

OK, that works. But this works better:

––begin derived table (er, named query) example, mumbo jumbo excluded
select CustomerName, CustomerAddress, CustomerCity, CustomerState, CustomerZIP
from Customer
inner join (select CustomerNumber from Orders where OrderDate >= DATEADD(dd, -90, GETDATE())) as Recent
on Customer.CustomerNumber = Recent.CustomerID
––end example, the named query (er, derived table) is bold

Every time you use a temp table you should carefully consider your options. Might you want a view instead? Or this, a derived table.

I can’t post the example I once sent to my team — it has too much proprietary information. But I once accomplished the same exact task this way that was once done using temp tables. Temp tables took over 9 minutes. Derived, 2.

I can’t explain why it is so much faster. I’m not a hardcore SQL engineer. But I think it has to do with tempdb and disk I/O.

Try it; you’ll like it.

Tags: , , ,

Leave a Comment

Interesting Blog Spam

I just noticed a very well done spam blog comment. Somebody appears to have some sort of bot that is scouring blogs for key words. It found mattmutz.com yesterday because of my post about my new iPod touch.

But I know it’s spam. Because when I went to their site to check it out (btw I didn’t click a link, I typed it in, because I don’t want to promote blog spamming) and It is a very well done list of posts about iPod, iPhone, Google Phone, last.fm, etc. A bunch of popular subjects. All of the posts list the title of the blog and have a sentence that looks human-typed but is clearly spam. Because a human wouldn’t post this:

[name/link deleted] created an interesting post today on An AdMob update
Here’s a short outline
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

View the rest of this top post [link deleted]

Tags:

Leave a Comment

iPod Touch: My First Impression

I’ve wanted an iPod touch since before first iPhone was officially announced. And now I’m posting from one.

I’m impressed. It is slicker than I thought it would be. Keyboard a little tough to master but I’ve read that it gets easier.

The only drawback I’ve found is that now I’m wondering if I should’ve gotten an iPhone.

Tags:

Comments (1)

Bye-bye, Time Warner!

I try to keep it clean here at my little experiment on the web, otherwise this title would have been, “F**k you, Time Warner!”

I quit cable. For good. Or at least as long as I can stand to be without it, which might only be until LOST comes back on next year.

Why?

I’m moving to a new apartment and stopped by the local office to get my service transferred. I paid my bill (thinking it really isn’t worth it) and asked for my service to be moved. But while I paid my bill a line of four people formed behind me, and the clerk got frustrated and said she didn’t have time, it was only her in the office. She wrote down a number and told me to call it, and shooed me out the door.

And then I began thinking. Now, admittedly part of my frustration might have been having to drive way out of my way because a main bridge in town is closed, but that’s beside the point.

I just paid over a hundred dollars, was treated rudely, and didn’t get what I want. And for what? Since the LOST season 4 finale, I have watched maybe an hour of TV in the last six months. One hour. Really all I use is internet. Hundred bucks a month for internet? Meh. I spend too much time online anyway. And have gotten nothing but poor customer service on the phone with them and then wasn’t treated well today. (To be fair, I’ve had nothing but excellent customer service at that office in the past. Today was not the normal and I could see the clerk had a lot to do. But that doesn’t make it OK to not satisfy a customer. They should have adequate staff to handle the traffic.)

And, sure I could call to transfer my service, but right now I can’t make calls from my phone. My phone is broken and I can make and answer calls, and speak, but I can’t hear the person on the other end. I don’t get audio.

I gathered my cable modem and DVR and returned to the office. I set the equipment on the counter and the clerk asked, “Moving?” I replied, “No, I quit.” She asked, “Why?” I replied, “I’m sick of it.” She said, “Me too.” I replied a snide, “I can tell.” She tossed my stuff onto a pile, handed me a receipt, and I walked away from Time-Warner, possibly for good.

It feels somewhat liberating. That’s a bill I’ve hated paying for years. Telecom companies are just so horrible to deal with.

So, I’m going to go offline for a while and use public wi-fi (as I am right now), friends’ connections, et cetera when i want to go online. For at least a month. Flush some bits from my system and do analog things for a while.

Tags: ,

Comments (1)