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 |
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-07-28 : 15:43:45
|
Hello,Suppose I have a query.SELECT TOP 5 ID,UNT FROM PWHERE LEFT(RIGHT(NO,7),3)='080' But the result of LEFT(RIGHT(NO,7),3) could be '80' or '080'.So how to modify the query?Thanks |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-07-28 : 16:00:41
|
| Can it have multiple values for this?WHERE LEFT(RIGHT(NO,7),3) in ('0008','008','08','8') |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-07-28 : 16:03:25
|
| Here's an idea: try it! Don't ask some stranger on some forum to test things for you, try it yourself, that's the best way to learn.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-07-28 : 16:07:30
|
| LEFT(x, 3) cannot equal '0008'You could also do: WHERE LEFT('000' + RIGHT(NO, 7), 3) = '080'Or maybe (not sure if this meets your requirements): WHERE LEFT(RIGHT(NO,7),3) LIKE '%80' |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-07-28 : 16:24:52
|
| or ... you could simply explain your requirements. It's always useful for everyone involved to have the requirements spelled out clearly and completely.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-07-28 : 16:28:39
|
| Well, actually the right side is a variable.I don't know its length.Its maximum length is 3.I tried this query but can't run.WHERE LEFT(RIGHT(NO,7),3) in ('00'+@x,'0'+@x,@x) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-28 : 21:08:03
|
[code]WHERE LEFT(RIGHT(NO,7), len(@VARIABLE)) = @VARIABLE[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|