FYI I got this error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
Msg 137, Level 15, State 2, Line 8
Must declare the scalar variable "@ts_now".
Msg 156, Level 15, State 1, Line 23
Incorrect syntax near the keyword 'AS'.
-------------------
A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html