The Select Statement and the Reverse Function in SQL

March 14, 2008

one comment

I found out today something quite peculiar, which I didn’t know up till now.


I have a table which has codes and names in it. The names are in Hebrew and need to be reversed. The table should have rows in it only if there exists a description for the code. It shouldn’t have codes in it that don’t have a description. This is my select statement and its result:


 


Which was weird, because why would I have a blank line for a code? I shouldn’t have a line for it at all in that case. Still, I needed to reverse the description as the Hebrew description should be read the other way around. So I did another select statement using the reverse function this time, and got this:



 


The “Pratim” field (the description) is of data type varchar, and the data in the row for the specific row I’m looking at begins with junk:



It seems that when you run a reverse function in SQL on a field of varchar which begins with junk, the result pane sees the junk first and shows you empty data. At the same time, if you run a reverse function in SQL on a varchar filed and the data in it ends with junk, then you get the up side of the same behavior as you get the data with the junk omitted.


I was amused to see the quirks that certain data can create quirks on a reverse function in such a simple “select” statement. Even more so, I enjoyed seeing how every minus will also have its plus…

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

one comment

  1. Miky SchreiberMay 7, 2008 ב 16:59

    Hey Ella,

    When you use hebrew in the DB engine you should use nvarchar. This will prevent this junk.

    Reply