Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebMatrix sql LIKE %

I am having trouble with the following query. It works when I execute it directly from WebMatrix with static parameters and returns a few rows, but not from my .cshtml page

var accounts = database.Query(
  @"SELECT Username, Email, row_count
  FROM (SELECT Username, Email, Count(0) OVER() as row_count, ROW_NUMBER() OVER(ORDER BY @0 DESC) as row_number 
  FROM UserProfile 
  WHERE Username LIKE %@1% AND Email LIKE %@2%) as accounts
  WHERE row_number BETWEEN @3 AND @4",
  new object[] { sort, username, email, start, end });

When I replace the LIKE parameters @1 and @2 with static values it works, but it does not ORDER BY parameter @0

like image 812
ambiguousPanda Avatar asked Mar 14 '26 14:03

ambiguousPanda


1 Answers

Use this in your sql:

LIKE '%' + @1 + '%'
like image 68
Joel Coehoorn Avatar answered Mar 17 '26 03:03

Joel Coehoorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!