Truncate result



Greetings all. Since I have newly found the CONVERT statement, I have tried
using it in other applications. What I need to do is change this
'8705-3PF01BK' to this '3PF01BK'. I used the same CONVERT statement as in my
last post and it worked. There is one problem. When I do this,
CONVERT(nvarchar(7), EWO, 101), it changes '8705-3PF01BK' to this '8705-3P'.
Is there a way to make the expression return the last 7 characters rather
than the first seven? Thanks.


Now I realize the '101' in my CONVERT is in reference to a date format. Now
I will use CAST(EWO AS nvarchar(7)). My original problem of needing to
return the last 7 rather than the first 7 characters still exists.

Robert Morley

For those types of truncations, you're better off not using CAST or CONVERT.
The functions you're looking for are LEFT, RIGHT, and SUBSTRING.

For what you're trying to do, you'd either want RIGHT(EWO, 7) or possibly
SUBSTRING(EWO, 6, 999). The first one says take the right-most 7
characters; the second one says take everything from the 6th character
onwards (to a maximum of 999 characters). Note that the "999" is a dummy
number that's presumed to be longer than your string could ever possibly
be...if you know that the string will only ever be 7 characters, then you
can put that instead of 999.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads