What's your sql server version? The code works on sql2k and sql2k5 in my testing.