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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Substring on big Int

Author  Topic 

Stan1978
Starting Member

31 Posts

Posted - 2011-09-22 : 08:03:49
Thanks for reading.

I have a 23 character length bigint and I need to select 2 characters that are 8 from the left.

I have been trying - substring (Trans,8,2)

What should I do as this doesn't work on bigints??

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-09-22 : 08:17:53
String Functions only work on strings, try

SUBSTRING(convert(varchar(23),Trans),8,2)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-22 : 08:20:00
"I have a 23 character length bigint"

You sure? Max BigInt is 9,223,372,036,854,775,807 which is Length=19 digits

but this would do the conversion that you want:

substring(LEFT(REPLICATE(' ', 23) + CONVERT(varchar(23), Trans),23), 8,2)

you would be better off using arithmetic integer-division and modulus functions to get specific digits from a numeric value though.
Go to Top of Page

Stan1978
Starting Member

31 Posts

Posted - 2011-09-22 : 08:23:33
Yes your right cant count!! But works perfectly thank you guys.
Go to Top of Page
   

- Advertisement -