case

MySQL Case in Select Statement with LIKE operator

青春壹個敷衍的年華 提交于 2019-12-02 19:53:56
Is it possible to combine the CASE statement and the LIKE operator in a MySQL SELECT statement? For Example, I am trying to query a database that stores data in a single column in either one of two formats (this is awful and hurts my head, but I cant change the data so it is what it is.). So sometimes the column numbers would have data like "6901xxxxxxxx" and sometimes it would have data like "91xxxxxxxxxxx". What I would like to do is query the data like so - SELECT CASE digits WHEN LIKE "6901%" THEN substr(digits,4) WHEN LIKE "91%" THEN substr(digits,2) END as "digits", FROM raw This

Using CASE in PostgreSQL to affect multiple columns at once

微笑、不失礼 提交于 2019-12-02 18:58:21
I have a Postgres SELECT statement with these expressions: ,CASE WHEN (rtp.team_id = rtp.sub_team_id) THEN 'testing' ELSE TRIM(rtd2.team_name) END AS testing_testing ,CASE WHEN (rtp.team_id = rtp.sub_team_id) THEN 'test example' ELSE TRIM(rtd2.normal_data) END AS test_response ,CASE WHEN (rtp.team_id = rtp.sub_team_id) THEN 'test example #2' ELSE TRIM(rtd2.normal_data_2) END AS another_example In my particular query there are 5 fields whose output depends on whether rtp.team_id = rtp.sub_team_id evaluates true. I'm repeating CASE statements with the same condition over and over. Is there any

How to use CASE alias in WHERE CLAUSE?

泪湿孤枕 提交于 2019-12-02 18:22:42
问题 I'm trying to put the "val" into where clause, but it returns error: Select ff.FormID, ff.FieldID, ff.FieldName, ff.Title, ff.DefaultValue, fv.Value, val = case fv.Value when null then cast(ff.DefaultValue as nvarchar) else fv.Value end, ff.DataType from (SELECT FormID, FieldID, FieldName, Title, DataType, DefaultValue FROM FormFields where FormID = '766A38D8-8058-42C6-AC46-A18C00D3C1DC' and DEL = 0) as ff left join (select FormID, FieldID, Value from FormValues where FormID = '766A38D8-8058

TSQL CASE with if comparison in SELECT statement

陌路散爱 提交于 2019-12-02 17:53:28
I would like to use CASE statement in SELECT. I select from user table, and (as one attribute) I also use nested SQL: SELECT registrationDate, (SELECT COUNT(*) FROM Articles WHERE userId = Users.userId) as articleNumber, hobbies, ... FROM USERS and then I would like to do a CASE statement to get rank of user (rank is dependent on articleNumber). I tried like this: SELECT registrationDate, (SELECT COUNT(*) FROM Articles WHERE Articles.userId = Users.userId) as articleNumber, ranking = CASE WHEN articleNumber < 2 THEN 'Ama' WHEN articleNumber < 5 THEN 'SemiAma' WHEN articleNumber < 7 THEN 'Good'

MS Access Query with CASE statement

半城伤御伤魂 提交于 2019-12-02 17:45:43
问题 I just want to get the value of one table "b" if table "a" value is "-" If the value at table "b" is empty then get the value of table "a" even if it's "-" Microsoft Access says "Missing operator" with this query: SELECT ts.data_generacio, ts.estat, ts.exercici, Month(tsl.data) AS Mes, Day(tsl.data) AS Dia, tsl.data, tsl.cod_treb, t.nom_treb, tsl.hores, p.cod_proj, p.acronim AS nom_proj, j.justificacio, tsl.timesheet_id, p.ref, CASE WHEN tsl.activitat != '' THEN tsl.activitat ELSE ts

Find path in bash on insensitive manner

此生再无相见时 提交于 2019-12-02 17:14:59
问题 Suppose a path like /home/albfan/Projects/InSaNEWEBproJECT Despite of the fact to not use such that names. Is there a way to check for a path in an insensitive manner? I came across to this solution, but I would like to find a builtin or gnu program, if it is possible. function searchPathInsensitive { # Replace bar with comma (not valid directory character allowing parse dirs with spaces) #also remove first / if exist (if not this create a first empty element ORG="$1" if [ "${ORG:0:1}" = "/"

how to use switch case like (if)?

自作多情 提交于 2019-12-02 17:04:29
问题 I want to use switch like if in my code but I dont know how to use && in case ! this is my code string a; a = System.Convert.ToString(textBox1.Text); if (a.Contains('h') && a.Contains('s')) { this.BackColor=Color.Red; } else if (a.Contains('r') && a.Contains('z')) { this.BackColor=Color.Black; } else if (a.Contains('a') && a.Contains('b')) { this.BackColor = Color.Pink; } 回答1: If you can user later versions of C# you can write it like this: switch (st) { case var s when s.Contains("asd") && s

What are the different kinds of cases?

纵然是瞬间 提交于 2019-12-02 17:01:24
I'm interested in the different kinds of identifier cases, and what people call them. Do you know of any additions to this list, or other alternative names? myIdentifier : Camel case (e.g. in java variable names) MyIdentifier : Capital camel case (e.g. in java class names) my_identifier : Snake case (e.g. in python variable names) my-identifier : Kebab case (e.g. in racket names) myidentifier : Flat case (e.g. in java package names) MY_IDENTIFIER : Upper case (e.g. in C constant names) Nils von Barth Names are either generic, after a language, or colorful; most don’t have a standard name

T-SQL - Using AND condition only if a value from a list is present

删除回忆录丶 提交于 2019-12-02 15:32:42
问题 I want to add an AND condition in my query after the WHERE clause only if I find (a) value(s) from a list of predefined values, otherwise the condition should not be added. The condition I want to add here is "AND Table2.fieldvalue = importantvalue" only when a parameter value is present in a list of (1001, 1002, 1003, 1004, 1005, 1006, 1007) Also the parameter that comes in is a STRING with INT values comma separated but I have a user defined function to split and cast it into INT SELECT

Mysql case not working

落爺英雄遲暮 提交于 2019-12-02 13:15:43
SELECT SQL_CALC_FOUND_ROWS a.* , zn.`name` AS zone_name, c.`name` AS carrier_name, CASE type WHEN type=1 THEN 'General day' ELSE 'Special date' END AS type_changed, CASE week_day WHEN week_day = -1 THEN 'notset' WHEN week_day = 1 THEN 'monday' WHEN week_day = 2 THEN 'tuesday' WHEN week_day = 3 THEN 'wednesday' WHEN week_day = 4 THEN 'thursday' WHEN week_day = 5 THEN 'friday' WHEN week_day = 6 THEN 'saturday' WHEN week_day = 7 THEN 'sunday' END AS week_day_mod , IF(date = '0001-01-01 00:00:0', '--', DATE(date)) AS date_mod, IF(is_working_day = 1 ,'working day', 'day off') AS is_working_day_mod