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 |
|
Kift
Starting Member
14 Posts |
Posted - 2008-11-07 : 11:15:36
|
| Hello again.Sorry to say I'm back with another problem which I could use your expert with.I've got an issue with postcodes in that spaces can occur in various different places and can increase the length of the field.In order to cope with this, I used the replace function to remove all spaces from the postcode variable and I am now left with a field that is either 5,6 or7 characters long.What I need to with this is to isolate the last 3 characters, such as 3TT, from any of the postcodes I now have. The problem, is that as the postcodes are different lengths I can't just a right function to return the last three characters as somtimes I get three needed, some times I get a space and 2 characters.Is there a way I can return the last three characters of the field regardless of the length. Here are some examples of the postcode variable I have created.IG145RTKJ678TYHG678TYGH56EFRT249YUG37RTRT456TYand so on.Many thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 11:18:42
|
| is this what you want?SELECT RIGHT(RTRIM(postcode),3) FROM Table |
 |
|
|
Kift
Starting Member
14 Posts |
Posted - 2008-11-07 : 11:47:22
|
| Perfect.Thanks very much. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-07 : 11:51:00
|
cheers |
 |
|
|
|
|
|