case

Using CASE in PostgreSQL to affect multiple columns at once

微笑、不失礼 提交于 2019-12-03 05:39:08
问题 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

MySQL Case in Select Statement with LIKE operator

眉间皱痕 提交于 2019-12-03 05:26:10
问题 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

Regarding Java switch statements - using return and omitting breaks in each case

喜夏-厌秋 提交于 2019-12-03 05:23:51
问题 Given this method, does this represent some egregious stylistic or semantic faux pas: private double translateSlider(int sliderVal) { switch (sliderVal) { case 0: return 1.0; case 1: return .9; case 2: return .8; case 3: return .7; case 4: return .6; default: return 1.0; } } It's clearly not in line with the Java tutorials here. However, It's clear, concise and so far has yielded exactly what I need. Is there a compelling, pragmatic reason to create a local variable, assign a value to it

TSQL CASE with if comparison in SELECT statement

限于喜欢 提交于 2019-12-03 04:43:32
问题 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

What are the different kinds of cases?

删除回忆录丶 提交于 2019-12-03 03:31:06
问题 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) 回答1:

T-SQL Where Clause Case Statement Optimization (optional parameters to StoredProc)

荒凉一梦 提交于 2019-12-03 02:56:56
I've been battling this one for a while now. I have a stored proc that takes in 3 parameters that are used to filter. If a specific value is passed in, I want to filter on that. If -1 is passed in, give me all. I've tried it the following two ways: First way: SELECT field1, field2...etc FROM my_view WHERE parm1 = CASE WHEN @PARM1= -1 THEN parm1 ELSE @PARM1 END AND parm2 = CASE WHEN @PARM2 = -1 THEN parm2 ELSE @PARM2 END AND parm3 = CASE WHEN @PARM3 = -1 THEN parm3 ELSE @PARM3 END Second Way: SELECT field1, field2...etc FROM my_view WHERE (@PARM1 = -1 OR parm1 = @PARM1) AND (@PARM2 = -1 OR

《oracle pl/sql程序设计》学习笔记一

↘锁芯ラ 提交于 2019-12-03 02:08:03
本篇主要是记录一些容易混淆或者以前理解不够清楚的知识点,只选择常用知识点。 一、case语句和case表达式 1、case语句和case表达式都有两种模式:简单型和搜索型。 简单型:case exp when res1 then ... res2 then ... [else ...] (end case |end); 搜索型 :case when exp1 then ... exp2 then ... [else ...] (end case |end). 2、区别 case语句没有匹配项会报错;case表达式不会,返回null。 case语句以end case结尾;case表达式以end结尾。 二、for循环只有数值型下标和游标两种方式循环,数值型的上下标只在第一次循环前求值(包括表达式计算和四舍五入)。 三、11g以后新增了continue [label1] [when exp1]语句,用于执行下一个循环。 四、异常处理 1、sqlcode 获取当前异常号,正常为0. 2、sqlerrm 最原始的异常信息获取方式,最大512字节。不带参数时返回当前sqlcode对应的信息。带参数时返回指定sqlcode的信息。 3、dbms_utility.format_error_stack 比sqlerrm可容纳字节多,达1899字节,只能返回当前sqlcode对应的信息。 4、dbms

Using || in Case switch in Rails

喜夏-厌秋 提交于 2019-12-02 23:28:23
I have a partial that I want to display in a layout only when certain pages use that layout. I've set @page_title for all my pages and thought I could use something like this: <% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%> But, the include is only happening on the page titled "Log in" and not the other pages. Are || statements like this not allowed on Case switches? Is there a different way to set an OR statement in the case switch? Thanks! This is what you want: <% case @page_title when "Log in

CASE statement in SQLite query

南楼画角 提交于 2019-12-02 19:59:47
Why this query doesn't work? :( I tried to replace nested IF statement "...SET lkey = IF(lkey >= 11, lkey - 5, IF(lkey > 5, lkey + 2,lkey))" UPDATE pages SET lkey = CASE lkey WHEN lkey >= 11 THEN lkey - 5 ELSE CASE lkey WHEN lkey > 5 THEN lkey + 2 ELSE lkey END END, rkey = CASE lkey WHEN lkey >= 11 THEN rkey - 5 ELSE CASE rkey WHEN rkey < 11 THEN rkey + 2 ELSE rkey END END WHERE rkey > 5 AND lkey < 12; 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

SQL changing a value to upper or lower case

谁都会走 提交于 2019-12-02 19:54:56
How do you make a field in a sql select statement all upper or lower case? Example: select firstname from Person How do I make firstname always return upper case and likewise always return lower case? SELECT UPPER(firstname) FROM Person SELECT LOWER(firstname) FROM Person Stephen Wrighton LCASE or UCASE respectively. Example: SELECT UCASE(MyColumn) AS Upper, LCASE(MyColumn) AS Lower FROM MyTable SQL SERVER 2005: print upper('hello'); print lower('HELLO'); You can use LOWER function and UPPER function . Like SELECT LOWER('THIS IS TEST STRING') Result: this is test string And SELECT UPPER('this