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
Use this in your sql:
LIKE '%' + @1 + '%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With