case

Using CASE for WHERE field IN

▼魔方 西西 提交于 2019-12-10 20:12:46
问题 The following is not a "correct way" to do it, but rather a demonstration for what I'm trying to achieve: SELECT [...] FROM [...] WHERE condition1 AND condition2 AND field IN CASE (@type) WHEN 1 THEN (SELECT subquery #1) WHEN 2 THEN (SELECT subquery #2) WHEN 3 THEN (SELECT subquery #3) END Meaning, I want a different sub-query for each different value for the parameter @type . What would be a good way to do it? 回答1: Try this SELECT [...] FROM [...] WHERE condition1 AND condition2 AND ((@type

CASE Statement in SQL WHERE clause

痞子三分冷 提交于 2019-12-10 15:03:59
问题 I'm trying to fetch data from table where I'm using a CASE condition in the WHERE clause and currently I'm using following query:- SELECT count(enq_id) AS total, sum(purchase_amount) AS purchase FROM temp_stock WHERE purchase_date <> '0000-00-00' AND purchase_date < '2012-08-01' AND ( STATUS = 'Sold' OR STATUS = 'In Stock' OR STATUS = 'Ref' ) AND CASE WHEN ( STATUS = 'Sold' ) THEN delivery_date >= '2012-08-01' END But it returns 0 for total and NULL for purchase . 回答1: From your comment. I

Using CASE to create new column based on specific text in a string column

独自空忆成欢 提交于 2019-12-10 14:38:16
问题 I found a couple similar threads, but none are working. I'm trying to create a new column for when another column satisfies a certain condition. This is the code I'm working with: SELECT DISTINCT R.[Column1] AS Person, SUM(CASE WHEN R.[Event] = 'Event1' THEN 1 ELSE NULL END) AS Event1, CASE (WHEN L.[Column2] LIKE '%String1%' THEN 'String1' ELSE WHEN L.[Column2] LIKE '%String2%' THEN 'String2' ELSE WHEN L.[Column2] LIKE '%String3%' THEN 'String3' ELSE NULL END) AS NewColumn FROM [Database1].

MySQL View check if data is NULL

妖精的绣舞 提交于 2019-12-10 13:40:09
问题 I need to put a Case in the Select to check if the Data I'm adding to my view is NULL, in which case I want it to just enter a zero, or not. 回答1: You mean something like this? SELECT IF(`field` IS NULL, 0, `field`)... There's also "IFNULL()": SELECT IFNULL(`field`, 0)... 回答2: select coalesce(field, 0) as 'field' from v; (doc) 回答3: When creating your table just add NOT NULL to the column description, e.g. CREATE TABLE ( ID INT NOT NULL default '0' ); Then if no data is given for the field it

Xquery: same test has different result whether used in switch/case or in if/then/else

泪湿孤枕 提交于 2019-12-10 13:35:13
问题 I can't find an explanation on the following. I've made this test script in order to solve my previous question. xquery version "3.0" ; declare default function namespace 'local' ; declare function local:is-img-only( $element as element() ) as xs:boolean { ($element/child::*[1] instance of element(img)) and (fn:not($element/child::*[2])) and (fn:normalize-space($element) = '') } ; let $in-xml := <myxml> <p id="1"> <img id="1"/> </p> <p id="2"> <img id="1"/> hello </p> <p id="3"> <img id="1"/>

T-SQL SYNTAX ISSUE - using OR in CASE statement

本小妞迷上赌 提交于 2019-12-10 12:59:12
问题 i would like to build a CASE statement that incorporates the following logic, but the sql compiler does not like the 'OR' in my statement: CASE expression WHEN expression1 OR expression2 THEN <yadda yadda> ELSE <yadda yadda> END more specific code below: CASE @var1 WHEN '99' OR '22' THEN (CASE @var2 WHEN 'All' THEN col1 ELSE @var2 END) END 回答1: DECLARE @Variable INT; SET @Variable = 1; SELECT CASE WHEN @Variable = 1 OR @Variable = 2 THEN 'It is 1 or 2' WHEN @Variable = 3 THEN 'It is 3' ELSE

An update with multiple conditions. SQL 2008

怎甘沉沦 提交于 2019-12-10 12:23:50
问题 I have a table... ProjectID UserID RoleID 101 1 10 101 2 10 102 2 10 102 3 10 103 1 10 Currently there is only one type of Role, role '10', but I'm wanting to add a new role, role '11', which will act as a lead. So any project that has a user with the role of '10', should have a lead. The user chosen to be lead will be based on a priorty list, in this example we'll say the order is 1, 2, 3. Expected result... ProjectID UserID RoleID 101 1 11 101 2 10 102 2 11 102 3 10 103 1 11 回答1: You can

MySQL Query WHERE Including CASE or IF?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 09:37:45
问题 Strange problem. My Query looks like SELECT DISTINCT ID, `etcetc`, `if/elses over muliple joined tables` FROM table1 AS `t1` # some joins, eventually unrelated in that context WHERE # some standard where statements, they work/ CASE WHEN `t1`.`field` = "foo" THEN (`t1`.`anOtherField` != 123 AND `t1`.`anOtherField` != 456 AND `t1`.`anOtherOtherField` != "some String") WHEN `t1`.`field` = "bar" THEN `t1`.`aSecondOtherField` != 12345 END #ORDER BY CASE etc. Standard Stuff Apperantly MySQL returns

Android: Button OnClickListener does not working

社会主义新天地 提交于 2019-12-10 03:16:54
问题 I have created this activity that should allow me to open a new activity once a button has been pressed. However the OnClickListener does not seem to be working. Am I declaring the buttons wrong? Can someone me out? public class Menu extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu); View loginbutton = findViewById(R.id.butlogin); loginbutton.setOnClickListener(this); View recordbutton =

intent to activity in Side-Menu.Android of material design

我们两清 提交于 2019-12-09 17:25:55
问题 in https://github.com/Yalantis/Side-Menu.Android please help me :( How can when i click on each item in side menu, go to command "intent to other activity" instead of transport between images import android.content.res.Configuration; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarDrawerToggle; import