In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

I want to conduct a search in SQL table using like command.

But I have problem conduct it on these below range:

range1 (491,491.0-491.9,492,492.0,492.8, or 496);

range2 ( 398.91,402.01,401.11,402.91,428.xx);

range3 (401.00, 401.1, or 401.9 and**without range2**)

Could you please help me in these ones.

Thank you very much!

With the content is 250.xx, it is easy, like:

select count(number) from table1 where value1 like '250%'

select count(number) from table1 where value1 like '250%'

With (410.xx-414.xx), I can use:

select count(number) from table1 where value1 like '41[0-4]%'

select count(number) from table1 where value1 like '41[0-4]%'

But I have problem conduct it on these below range:

range1 (491,491.0-491.9,492,492.0

range2 ( 398.91,402.01,401.11,402.9

range3 (401.00, 401.1, or 401.9 and

Could you please help me in these ones.

Thank you very much!

Are these ranges in table columns, if yes then what are you trying to search for???

http://www.sql-tutorial.net/SQL-LIKE.asp

Do you get my question?

like should be applied if the data is varchar. if you can do comparisons by coverting the data in numeric(signed/unsigned), one should use between and other arithmetic operators

491

491.0-491.9,

492

492.0

492.8

496

Outside, do not count, for example 492.0 and 492.8 count but 492.6 492.7 does not count.

I think that I explain my question enough to understand.

and so on

Thanks

http://www.craigsmullins.com/ssu_0899.htm

http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx

select count(number) from table1

where value1 like '491' or value1 like '418.[0-9]%'

or value1 like '492' or value1 like '492.[0-8]%'

or value1 like '496'

> range1 (491,491.0-491.9,492,492.0

It is not immediately obvious whether you wanted to include

491.02,

491.0 (exactly)

491 (exactly)

491.xx (will there be alpha?)

491.93 (491.93 is outside of 491.0 and 491.9 as a numeric range, but does 491.9 mean 491.9-anything?)

etc

You need to be very clear with your question

I just need to specify the value and connect it using or, that's all I need, it's not so complicate I think.

range1 (491,491.0-491.9,492,492.0

select sum(something) as sumtot from table1 where diag1 = '491' or diag1 like '491.[0-9]' or diag1 = '492' or diag1 = '492.0' or diag1 = '492.8' or diag1 = '496'

range2 ( 398.91,402.01,401.11,402.9

select sum(something) as sumtot from table1 where diag1 = '398.91' or diag1 = '402.01' or diag1 = '401.11' or diag1 = '402.91' or diag1 like '428%'

range3 (401.00, 401.1, or 401.9 and without range2) with range2 is ( 398.91,402.01,401.11,402.9

This query below does not works, please help me fix it cyberwiki:

```
select count(distinct something) from table1 where diag1 = '401.00' or diag1 = '401.1' or diag1 = '401.9' and diag1 <> '398.91' and diag1 <> '402.01' and diag1 <> '401.11' and diag1 <> '402.91' and diag1 not like '428%'
```

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

So range3 should just be

where diag1 in ('401.00', '401.1', '401.9')

You can use IN when using exact values and don't need LIKE.