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.
Here is the sample Data
ID data
----------- --------------------
1 Jacob
2 Sebastian
Here is the expected result
id data
----------- --------------------
2 naitsabeS
1 bocaJ
Use the script below to create the sample table.
DECLARE @t TABLE( ID INT IDENTITY, data VARCHAR(20))
INSERT INTO @t(data) SELECT 'Jacob'
INSERT INTO @t(data) SELECT 'Sebastian'
Notes:
- Write a single query that produces the expected result. No User Defined Functions allowed.
- 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.
- No restriction on SQL Server version. You can write the query for SQL Server 2000, 2005 or 2008
- Make sure that the subject of your email is ‘TSQL Challenge 3’
- Last date to submit your entries: 31 March 2009