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 - 2010-03-17 : 14:39:57
|
Hi,I have a very simple script.select * from A join BON A.CODE=B.CDWHERE B.CD = 1 The question is that A.CODE = 'E_CASH' OR 'Fr_CASH'But B.CD = 'CASH'I don't know how to extract the substring 'CASH'.Thanks |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-17 : 14:43:50
|
tryon a.code like '%'+b.cd+'%' No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
ray-SQL
Starting Member
18 Posts |
Posted - 2010-03-17 : 14:44:00
|
| [code]Select * from A INNER JOIN BON RIGHT(A.CODE, 4) = B.CDWHERE B.CD=1[/code]This will only work if 'CASH' is always the last 4 characters of A.CODE.BTW, why is "B.CD=1"? If B.CD='Cash'?How to ask good questions that get answers:http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxRay Dai |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2010-03-17 : 14:51:05
|
Sorry, it should beselect * from A inner join BON A.CODE=B.CDWHERE B.DESCR = 1 btwON RIGHT(A.CODE, 4) = B.CDis not good for me.Because there are other cases which likeA.CODE = 'E_Credit Card' OR 'Fr_Credit Card'and B.CD = 'Credit Card' etc.Anyway, the substrings are same after '_'. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-03-17 : 14:52:21
|
did you try my approach? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2010-03-17 : 14:58:42
|
| Yes. Great. |
 |
|
|
|
|
|