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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Digit Check

Author  Topic 

igorblackbelt
Constraint Violating Yak Guru

407 Posts

Posted - 2006-01-31 : 16:44:24
Hey Guys -
I have a field, (Customer Number) 15 character long, there's an indicator on the 4th character that tells me what type of account that is, how can I use SQL to read that digit, just that character ?

123456789012345

---

Thanks!
Igor.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-01-31 : 16:51:38
You can use SUBSTRING to get that digit.

SELECT SUBSTRING(Column1, 4, 1)
FROM ...

Tara Kizer
aka tduggan
Go to Top of Page

rav3n0u5
Yak Posting Veteran

88 Posts

Posted - 2006-01-31 : 22:54:13
This is a dumb little point, but depending on what you are doing with that data - make sure you CAST (or Convert) it if you plan on using it in numeric form.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-01-31 : 23:49:32
SQL Server will implicitly convert char to numeric when necessary, so an explicit CAST is not required.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-01 : 09:30:29
and this will explain you clearly

SELECT cast(SUBSTRING('123456789012345', 4, 1) as int)*6 as intValue
SELECT SUBSTRING('123456789012345', 4, 1)*6 as intValue

select 'This month is '+cast(datename(month,getdate()) as varchar(12)) as ThisMonth
select 'This month is '+datename(month,getdate()) as ThisMonth


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -