Does this really need to be raw SQL? In my experience this is just a maintenance nightmare.