case

Eliminating NULLs when using CASE in SQL Server SELECT statement

和自甴很熟 提交于 2019-12-13 16:14:09
问题 I have a large, messy report to write that joins across 5 tables. There is one column in one table that is being used for several different values--essentially a "tag" column, where the tags are used in creative ways depending on what kind of miscellaneous metadata the users want to use. As a result, my query for the report returns 3 nearly-identical rows that differ only in the "tag" column; for instance, I might get: NAME TAG EMAIL BOB A BOB@EXAMPLE.COM BOB B BOB@EXAMPLE.COM BOB C BOB

Group By Column Alias

懵懂的女人 提交于 2019-12-13 14:28:59
问题 I want to group an sql statement by a column alias. In essense, I want the below to function as it should logically, but grouping by a column created with an as is not allowed. (Invalid column name). Anyone got any tips? SELECT CASE WHEN Date IS NULL THEN 'EMPTY' ELSE CASE WHEN Date = '1/1/1753' THEN 'UNAVAILABLE' ELSE CAST(MONTH(Date) as varchar(MAX))+ '/'+ CAST(YEAR(Date) as varchar(MAX)) END END AS MonthYear FROM tbltablename GROUP BY MonthYear 回答1: For the immediate problem of the

Selecting columns that are not all null

六眼飞鱼酱① 提交于 2019-12-13 10:31:46
问题 So I have a query that looks like this - select case when @subType = 1 or @subType = 2 then id end as Id, case when @subType = 3 then name end as name case when @subType = 3 or @subType = 2 then address end as address from table So the issue I have is, that if @subType is 3, then the column named ID will all be null. I then don't want to return this entire column. Conversely to that, if @subType is 2, then name would all be null so I don't want that entire column. 回答1: The only way you could

C Looping a switch using Y/N options. Choosing N doesn't close the program

我只是一个虾纸丫 提交于 2019-12-13 09:55:33
问题 I've only started coding C. (freshman here, no experience, only basic html) For some reason, whenever I choose the option 'N', it just creates a new line. At my second scanf whenever I change my '%s' , the result changes. When I use, "%d" ,after entering a number, it continuously enter " Choose a number between 1-4 ". If I use "%c" ,after entering a number, it will skip directly to the loop. Help? #include <stdio.h> int main() { int n, ok = 0; char input; while (ok == 0) { printf("Choose a

SQL Server 2012: How to display the @Var result inside a Case statement with literals before and after the @Var

江枫思渺然 提交于 2019-12-13 09:45:15
问题 SQL Server 2012: how to display the @Var result inside a Case statement with literals before and after the @Var ? A simple query: Declare @Var1 ... Declare @Var2.... Select .... CASE WHEN ........... THEN 'Display this sentence ' + @Var1 +'followed by there words' ELSE 'Display these other words ' +@Var2 'followed by these other words' END The error message is 'Display this sentence' is not a declared variable. I know it isn't! It should be a literal statement, only with the @Var1 result

Multiple characters in a switch statement?

梦想的初衷 提交于 2019-12-13 09:28:14
问题 just to clarify this is hw. In a project we're doing, a user isn't allowed to enter numbers or special characters (i.e ! @ £ etc) char letter; String phonetic; Scanner kb = new Scanner(System.in); System.out.print("Please enter a letter: "); letter = letter = kb.next().charAt(0); switch(Character.toUpperCase(letter)) { case 'A': { Dot(); Dash(); Red(); } break; case '1,2,3,4,5,6,7,8,9,0': { System.out.println('No number input please!'); } break; } The error is on '1,2,3,4,5,6,7,8,9,0' Eclipse

Dead branch in if else statement

 ̄綄美尐妖づ 提交于 2019-12-13 09:09:15
问题 I'm writing this code where you give the the program a name. Java is telling me that the else in the statement is never used when it should be used if the variable "isACoolGuy" is false. if (isACoolGuy = true){ System.out.println("Thank you for this name... "+ name); }else if(isACoolGuy = false){ System.out.println("Okay im changing my name since you are an idiot"); name = name = "jack"; System.out.println("My name is "+ name + " now"); There is a switch statement earlier that should change

Sprade distinct values over a different columns

不问归期 提交于 2019-12-13 09:07:45
问题 I'm using SQL Server. I have the following table ( MyTable ): ID (int) value (varchar) I have the following query: select distinct value from MyTable And the output is: Value_1 Value_2 Value_3 ... ... ... Value_450 I would like to crate the following table (when value = 'value_1' then 1 else o...): ID | Value_1 | Value_2 | Value_3 | Value_4 | .... | Value_450 1 | 0 | 1 | 0 | 0 | .... | 0 2 | 0 | 0 | 0 | 1 | .... | 0 3 | 1 | 0 | 0 | 0 | .... | 0 4 | 0 | 1 | 0 | 0 | .... | 0 5 | 0 | 0 | 0 | 0 |

UPDATE NESTED CASE

梦想与她 提交于 2019-12-13 06:59:41
问题 I am using TOAD which connects to Oracle 11g. I am working on parsing an address field, which will contain building number, street name, street type, direction, sub-unit, and Civic Number Suffix Type. Because of the complexity in how address's are allowed to be entered and still be valid (or just having incorrect information which Im ignoring for now) I am having to do some very specific regular expressions to break apart the building number, sub-unit, and Civic Number Suffix Type. I have

MYSQL stored procedure, case

感情迁移 提交于 2019-12-13 04:35:13
问题 I've consulted this page: http://dev.mysql.com/doc/refman/5.1/en/case.html as well as this one, but can't get a simple procedure to work.... UPDATE: To clearify what I want to do: I want to select all rows from a table where the field id is either 1, 0 or could be either of them. This is specified by an input parameter to the procedure, which takes values 0,1 or 2. So if _id = 0 I want: select * from TABLE where id = 0 If _id = 1 I want: select * from TABLE where id = 1 And if _id = 2 I want: