Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2008-12-10 : 13:00:42
|
| Hello;We have a table where each field from a column is 5 chars. Recently I was asked to write a simple query to extract the 2 rightmost characters.so before extraction the values in employeeID would be represented as:10000100012000020001etc..However this query returns nothing (blank fields)select left(employeeID,2) from pjemployWhile this query returns what I expectselect right(left(employeeID,5),2) from pjemployoutput:00010001Why is it that I needed to combine the right and left functions together? Shouldn't I have been able to use left by itsef as in the first query? Again these are just chars with a guaranteed length of 5.Nothing significant about the datatype in my view..Do I miss something obvious?r&r |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-12-10 : 13:45:13
|
| unless you specify column length 5 you will need to RTrim the column. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-10 : 21:05:25
|
| try like belowRIGHT(LTRIM(RTRIM(yourfield)),2) |
 |
|
|
|
|
|