You'll be even prouder to get it working in SQL then ;)