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
 Selecting specific digits in a number

Author  Topic 

Jason2112
Starting Member

17 Posts

Posted - 2009-06-30 : 14:11:00
I have an nvarchar field (size=4) that is used to identify an item number. The item number is made up of 3 distinct identifiers: family (digit 1), class (digit 2), sub-class (digits 3-4). I need some help with creating the select statement to look at each digit in the field. Probably easy, but I couldn't find anything in older posts. Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-30 : 14:12:43
What do you mean with "Look at each digit"?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-30 : 14:13:26
[code]
SELECT LEFT(field,1) AS family,SUBSTRING(field,2,1) AS class,RIGHT(field,2) AS sub_class
FROM YourTable
[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-06-30 : 14:16:56
1. Why NVARCHAR?
2. Why VARCHAR at all?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Jason2112
Starting Member

17 Posts

Posted - 2009-06-30 : 15:29:40
quote:
Originally posted by visakh16


SELECT LEFT(field,1) AS family,SUBSTRING(field,2,1) AS class,RIGHT(field,2) AS sub_class
FROM YourTable




Thank you that worked perfect!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-01 : 11:52:34
welcome
Go to Top of Page
   

- Advertisement -