T-SQL Challenge #3

This puzzle is part of the TSQL Challenge contest.

Author: Jacob Sebastion

Introduction

This challenge is not for solving any business/application problem, but just to refresh your TSQL skills on set based operations.

So, the task is to reverse a string without using the REVERSE() function. What is wrong with the REVERSE() function? Nothing Really! As I mentioned earlier, this is to refresh your TSQL skills on set based operations. In real life, you should always use the REVERSE() function, if ever you need to reverse a string.

Again, we are not going to reverse a single string. We need to reverse all the values in the column of a table using a single query.

Sample Data

ID          data
----------- --------------------
1           Jacob
2           Sebastian

Expected Results

ID          data
----------- --------------------
2           naitsabeS
1           bocaJ

Rules

Sample Script

DECLARE @t TABLE( ID INT IDENTITY, data VARCHAR(20))
INSERT INTO @t(data) SELECT 'Jacob'
INSERT INTO @t(data) SELECT 'Sebastian' 

SELECT * FROM @t

Restrictions

Notes

  1. Write a single query that produces the expected result. No User Defined Functions allowed.
  2. Make sure that your code works with the sample script given above. Use the same column names, table variable name etc. This makes my life easier while testing the code.
  3. No restriction on SQL Server version. You can write the query for SQL Server 2000, 2005 or 2008