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
 using str function

Author  Topic 

issammansour
Yak Posting Veteran

51 Posts

Posted - 2007-09-28 : 16:48:15
Hi,

I have an item number as column on my table, this column is a char(10) size. Its look like this.

Item_no
-------
010010001
010010002
010010003
010020001
010020002
020020001

The description of the field as follows:-

xx is the catcode
xxx is a subcode
xxxxx is the serial number

How to search the table look for item number with subcode of '002', normally we are using before str() function.

Best Regards


Lumbago
Norsk Yak Master

3271 Posts

Posted - 2007-09-28 : 17:32:00
select * from table where substring(item_no, 3, 3) = '002'

--
Lumbago
"Real programmers don't document, if it was hard to write it should be hard to understand"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-29 : 04:44:38
select * from table where item_no LIKE '__002%'

may be faster, although the leading wildcards may preclude that.

It would be better to change your table structure so that this single field was not overloaded with three separate pieces of data, and put them in individual fields instead.

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-03 : 03:32:17
or

item_no like '[0-9][0-9]002%'

Madhivanan

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

- Advertisement -