By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,419 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,419 IT Pros & Developers. It's quick & easy.

LIKE usage

P: 2
Hi,

I am doing this query succesfully in MySQL and I wonder why the LIKE does not work the same in MSSQL. Is there any way arround?

MySQL: SELECT * FROM tariffs WHERE '4321' LIKE concat(prefix,'%')

MSSQL: SELECT * FROM tariffs WHERE '4321' LIKE (prefix + '%')

the MSSQL query returns NULL always.
The long workarround is to make a: WHERE prefix = '4321' OR prefix = '432' OR prefix = '43' OR prefix = '4'
but I want to avoid this.

Anybody knows a workaround?

Thanks
Oct 22 '08 #1
Share this Question
Share on Google+
2 Replies


P: 2
Ok, I found the solution.
Using RTRIM like this it works:

SELECT * FROM tariffs WHERE '4321' LIKE RTRIM(prefix) + '%'
Oct 22 '08 #2

ck9663
Expert 2.5K+
P: 2,878
Ok, I found the solution.
Using RTRIM like this it works:

SELECT * FROM tariffs WHERE '4321' LIKE RTRIM(prefix) + '%'

Your where clause:

Expand|Select|Wrap|Line Numbers
  1. WHERE prefix = '4321' OR prefix = '432' OR prefix = '43' OR prefix = '4'
  2.  
is similar to

Expand|Select|Wrap|Line Numbers
  1. WHERE PREFIX like '4%'

-- CK
Oct 22 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.