case

removing null value from string

允我心安 提交于 2019-12-12 04:57:09
问题 I want to show the translated name and description with language_id 'us' and 'ru'. My question is how can I remove the null values? SELECT DISTINCT CASE WHEN LANGUAGE_ID = 'US' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ') END AS PRODUCT_NAME_US, CASE WHEN LANGUAGE_ID = 'US' THEN INITCAP(CONCAT(SUBSTR(TRANSLATED_DESCRIPTION, 1, 30), '...')) END AS PRODUCT_DESC_US, CASE WHEN LANGUAGE_ID = 'RU' THEN COALESCE(TO_CHAR(TRANSLATED_NAME), ' ') END AS PRODUCT_NAME_RU, CASE WHEN LANGUAGE_ID = 'RU' THEN

Populate a column in SQL Server by weekday or weekend depending on the datetime

99封情书 提交于 2019-12-12 04:53:34
问题 I am working on SQL Server, wherein I cannot update any existing column nor can I add any more data/ column to the data. I have a column of dttime (yyyy-mm-dd hh:mm:ss) which consists of the date time value against each entry. I want to select the existing columns , and a new column as wd which will be populated as 'weekend' when the day of the week is either Saturday or Sunday and 'weekday' in case of other days I am using the below query: SELECT id, total, case when dayofweek(dttime) in (1

Using a CASE with the IN clause in T-SQL

柔情痞子 提交于 2019-12-12 04:53:19
问题 In My WHERE Clause I am using a CASE that will return all rows if parameter is blank or null. This works fine with single valuses. However not so well when using the IN clause. For example: This works very well, if there is not match then ALL records are returned! AND Name = CASE WHEN @Name_ != '' THEN @Name_ ELSE Name END AND This works also, but there is no way to use the CASE expression, so if i do not provide some value i will not see any records: AND Name IN (Select Names FROM Person

Hammer.js skips 'case' inside 'switch'

余生颓废 提交于 2019-12-12 04:50:59
问题 After updating Hammer to v2 it doesn't recognize gestures anymore. It does trigger 'switch(event.type)' but skips all of the cases. Is 'case' not supported anymore? Example of the code: function handleHammer(event) { // disable browser scrolling event.preventDefault(); switch(event.type) { case 'tap': the_single_post.removeClass('grab'); var tapPos = (event.gesture.center.pageX) - (element.offset().left); if (tapPos > paneWidth/2) { hammer.next('easeinout'); } else if (tapPos < paneWidth/2) {

SQL - Row sum with condition from 2 tables

荒凉一梦 提交于 2019-12-12 04:31:14
问题 I have 2 tables and want to get the row sum from 2 tables with conditions. Here are my tables: tabale1, tabale2 i want the row sum from 2 tables, like: if sk not null sum sk but if it is null sk = ss For example, the total sum of sh2 is: 19 + 5 + 11 + 5 = 40 I really need that, please help! Table1: Table2: 回答1: Next sql will return the sum over the tables, grouping by name: select name, sum(total) total from (select name, sum(coalesce(sk,ss)) total from table1 group by name union all select

case statement logic [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:29:09
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Let's make this easy. I have a table. visitID studentname dob roll.no value displIndex propID 200019 rob 05/18/1937 101 smoking 2 83 200019 rob 05/18/1937 101 2 91 200019 rob 05/18/1937 101 alcohol 1 83 200019

How to use a CASE statement within a SELECT COUNT statement?

北城余情 提交于 2019-12-12 04:12:12
问题 I need to make a case statement. Depending on what the variables value is, it needs to select the correct column from the table StartDate and EndDate are different variables. There is a variable i created called Region which should determine what column the query selects. EDIT: Region can either be 'EW' for England and Wales, 'SC' for Scotland or 'NI' for Northern Ireland. If it is EW it should select column 1, SC for column 2, NI for column 3 SELECT COUNT(COLUMN1) FROM bankholidays WHERE

SQL Conditional AND

青春壹個敷衍的年華 提交于 2019-12-12 04:05:05
问题 I want to determine the AND clause based on the value of the current row. So for example, my job table has 4 date columns: offer_date, accepted_date, start_date, reported_date. I want to check against an exchange rate based on the date. I know the reported_date is never null, but it's my last resort, so I have a priority order for which to join against the exchange_rate table. I'm not quite sure how to do this with a CASE statement, if that's even the right approach. SELECT * FROM job j INNER

SQL: Add a new column based on CASE expression and looking up values from another table

丶灬走出姿态 提交于 2019-12-12 04:03:24
问题 I am trying to add a new column called Multiplier to an existing table called Trades. The row values of this column will depend on another column on the Trades table called Type. If the Type is anything other than "Equity", "Corp" or "Option, then the value needs to be looked up from another table called ContractSize. Lastly, I want the data type of the Multiplier column to be decimal (7,3). The code I had was: ALTER TABLE Portfolio.Trades ADD Multiplier decimal(7,3) AS ( CASE WHEN Type =

Why does the switch statement execute a case block even when a match is not found?

烈酒焚心 提交于 2019-12-12 03:58:08
问题 switch(1){ case 1: print 1; // prints 1 (as expected) case 2: print 2; // prints 2 (even though match is not equal?) case 3: print 3; // prints 3 (even though match is not equal?) } I know that most programming languages continue to execute each statement if you don't use break after each case expression match. But I'm confused as to why most languages execute a case block as a successful match on this second and third case statement. Just to clarify: I am aware of the behavior of the switch