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 |
|
dnf999
Constraint Violating Yak Guru
253 Posts |
Posted - 2007-01-08 : 07:07:28
|
| HiI have a numeric field and I need to to identify certain digits within the field.i.e. field1 1234567I need to pick out the first, second and last digits and add them up. I know that if the field was varchar i could simply use the substring syntax to obtain these, but as the field is numeric I was wondering if there is an equivalent method to get this...??Thanks in advance!! |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-08 : 07:31:23
|
| select field1 / power(10, len(field1) - 1) + field1 / power(10, len(field1) - 2) % 10 + field1 % 10Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-08 : 07:32:02
|
| Or simply CAST the integer field as VARCHAR first.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|