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 |
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2005-05-13 : 11:48:01
|
| I have a query that I want to do a where clause where it compare between to value, but want to use like in there.SELECT ID, DESCRIPTION, QTYFROM PARTWHERE (ID LIKE BETWEEN @STARTID + '%' AND @ENDID + '%')This is what I wanted, but the query is wrong though. Can someone help? |
|
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2005-05-13 : 12:02:51
|
| I have tried the following and it seems to work, but the end of parameter does not seem to be pulling correctly.SELECT ID, DESCRIPTION, QTYFROM PARTWHERE (ID BETWEEN @STARTID + '%' AND @ENDID + '%')For example if I put @STARTID = 'a' and @ENDID = 'b', it will only pull all from the A fields, but not the B. If I set it to C then it will pull all the Bs but not the Cs. Any ideas? |
 |
|
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2005-05-13 : 12:06:05
|
| Looks like I need to put the paranthesis in there with my other filters. Now it's working. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-05-13 : 13:44:48
|
| [code]USE NorthwindGOSELECT * FROM orders WHERE SUBSTRING(ShipName,1,1) >= 'A' AND SUBSTRING(ShipName,1,1) <= 'B'GO[/code]Brett8-) |
 |
|
|
chriskhan2000
Aged Yak Warrior
544 Posts |
Posted - 2005-05-13 : 17:04:32
|
| Thanks. That also worked. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-05-13 : 17:27:12
|
| no ... don't do that. no indexes. No need for LIKE or substring or anything odd. Remember of strings are compared, and how between works. Something as simple as:WHERE ShipName BETWEEN 'A' and 'B~'works fine.- Jeff |
 |
|
|
|
|
|
|
|