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 |
|
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 Kizeraka tduggan |
 |
|
|
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. |
 |
|
|
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. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-01 : 09:30:29
|
| and this will explain you clearlySELECT cast(SUBSTRING('123456789012345', 4, 1) as int)*6 as intValueSELECT SUBSTRING('123456789012345', 4, 1)*6 as intValueselect 'This month is '+cast(datename(month,getdate()) as varchar(12)) as ThisMonthselect 'This month is '+datename(month,getdate()) as ThisMonthMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|