Laravel Eloquent Select CASE?

Move your raw() call inside the SELECT statement: ->select(‘shares.id AS share_id’, ‘users.id AS user_id’, ‘shares.connected_user_id’, ‘shares.original_language_id’, ‘shares.image’, ‘users.first_name’, ‘users.last_name’, ‘users.email’, ‘locations.city’, ‘provinces.name’, ‘countries.code’, ‘locations.lat’, ‘locations.lng’, ‘shares.created_at’, DB::raw(‘(CASE WHEN users.id = ‘ . $user . ‘ THEN 1 ELSE 0 END) AS is_user’) ) ->orderBy(‘shares.created_at’, ‘desc’) From: https://laravel.com/docs/5.4/queries#raw-expressions

Convert string to Pascal Case (aka UpperCamelCase) in Javascript

s = s.replace(/(\w)(\w*)/g, function(g0,g1,g2){return g1.toUpperCase() + g2.toLowerCase();}); The regex finds words (here defined using \w – alphanumerics and underscores), and separates them to two groups – first letter and rest of the word. It then uses a function as a callback to set the proper case. Example: http://jsbin.com/uvase Alternately, this will also work – a … Read more

TSQL CASE with if comparison in SELECT statement

Please select the same in the outer select. You can’t access the alias name in the same query. SELECT *, (CASE WHEN articleNumber < 2 THEN ‘Ama’ WHEN articleNumber < 5 THEN ‘SemiAma’ WHEN articleNumber < 7 THEN ‘Good’ WHEN articleNumber < 9 THEN ‘Better’ WHEN articleNumber < 12 THEN ‘Best’ ELSE ‘Outstanding’ END) AS … Read more

Case Expression vs Case Statement

The CASE expression evaluates to a value, i.e. it is used to evaluate to one of a set of results, based on some condition. Example: SELECT CASE WHEN type = 1 THEN ‘foo’ WHEN type = 2 THEN ‘bar’ ELSE ‘baz’ END AS name_for_numeric_type FROM sometable` The CASE statement executes one of a set of … Read more

C# Switch-case string starting with

If you knew that the length of conditions you would care about would all be the same length then you could: switch(mystring.substring(0, Math.Min(3, mystring.Length)) { case “abc”: //do something break; case “xyz”: //do something else break; default: //do a different thing break; } The Math.Min(3, mystring.Length) is there so that a string of less than … Read more

CASE statement in SQLite query

The syntax is wrong in this clause (and similar ones) CASE lkey WHEN lkey > 5 THEN lkey + 2 ELSE lkey END It’s either CASE WHEN [condition] THEN [expression] ELSE [expression] END or CASE [expression] WHEN [value] THEN [expression] ELSE [expression] END So in your case it would read: CASE WHEN lkey > 5 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)