I haven’t done a puzzle for a long time so I figured let’s do a simple one. Return the right 6 characters of the column but without using the RIGHT function.
Here is what the table looks like
CREATE TABLE #Puzzle(SomeCol CHAR(7)) INSERT #Puzzle VALUES ('AAAAAAA') INSERT #Puzzle VALUES (' BBBBBB') INSERT #Puzzle VALUES ('CCCCCC') INSERT #Puzzle VALUES (' DDDDD ') INSERT #Puzzle VALUES (NULL) INSERT #Puzzle VALUES (' ')
As you can see some rows start with spaces and some end with spaces, one row has the NULL value
The output should be a Z followed by the right 6 characters from the column + the length of the column (not the length of the 6 characters that you are returning)
Here is what the output should look like
ZAAAAAA7 ZBBBBBB7 ZCCCCC 7 ZDDDDD 7 Z0 Z 7
As you can see spaces should remain and when the value is NULL then there should be a blank. The length for the row with the NULL value should be 0, you cannot hardcode 7 for the length, you have to calculate it.
Post your solution(s) in the comment section, remember no RIGHT function. Let’s see how many different ways you can come up with to do this