March 9, 2006 at 4:29 pm
I have a NBR field with 11 digits. I need to convert it to CHAR and then SUBSTRING the last 2 characters in a select statement. I've tried various combinations of CONVERT(CHAR,11),fieldname) and SUBSTRING(fieldname,9,2) and can't seem to get them nested together properly to display the last 2 positions.
I think this is the right combination, based on the Transact help documentation, but can't make it fly.
Any help will be appreciated.
TIA,
Joe
March 9, 2006 at 4:54 pm
declare @number bigint
set @number = 12345678911
select right(convert(char(11),@number),2)
March 9, 2006 at 5:18 pm
March 9, 2006 at 6:27 pm
Ray's suggestion should work for you. But using CONVERT and SUBSTRING, you would do this:
SELECT
SUBSTRING((CONVERT(CHAR(11),Fieldname)),9,2)
FROM tablename
The (CONVERT(CHAR(11), FieldName)) replaces the value that you want to 'substring'.
-SQLBill
March 10, 2006 at 5:10 am
Excuse me, could someone explain to me what data type is NBR? I suppose it is some number, but couldn't find anything more precise about it. Thanks!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply