Saturday, February 25, 2012

returning part of recordset

Hi, I have a table that has the following field and results.

I want a where clause that returns records that start 0000......

I need to exclude those records that start 0001........

Can anyone help

oseq
---
0000
0000.0000
0000.0000.0000
0000.0000.0000.0000
0000.0000.0000.0000.0000
0000.0000.0000.0000.0001
0000.0000.0000.0001
0000.0000.0001
0001
0001.0000
0001.0001
0001.0002
0000.0000.0002
0000.0000.0003
0000.0001
0000.0001.0000
0000.0001.0000.0000
0000.0001.0000.0000.0000
0000.0001.0000.0000.0000.0000
0000.0026.0004.0009
0000.0026.0004.0010You could use either the substring function or the like operator. Check BOL for more detail.

Tom|||Try like this

select * from test
where oseq like '0000%'

Roshmi Choudhury|||Roshmi's answer is simpler, and potentially much more efficient because it allows the query to use an index.

-PatP

No comments:

Post a Comment