case

What is better, dynamic SQL or where case?

半腔热情 提交于 2019-12-07 18:49:55
问题 I need to create a stored procedure which takes 12 arguments and the query is filtered with a different combination of this arguments. All 12 arguments are not mandatory as if I pass 3 or 5 or 12 arguments depends on search inputs entered by user. I can create 2 ways, either using a dynamic SQL query or using 'Case where' statements. Example of these queries are as below: Dynamic Query DECLARE @sql VARCHAR(MAX) DECLARE @condition VARCHAR(MAX)='' Declare @var1 varchar(10) Declare @var2 varchar

Is there a function to find all lower case letters in a character vector?

爷,独闯天下 提交于 2019-12-07 13:15:32
问题 I just wrote one, but I was wondering if one already exists in R. Here's the function BTW (suggestions for improvement are welcome): set.seed(50) x <- sample(c(letters, LETTERS), 7) is.lower <- function(x) { unlist(sapply(x, function(x2) {x2 %in% letters})) } is.lower(x) 回答1: grepl("[a-z]",x) for example? > grepl("[a-z]",x) [1] FALSE TRUE TRUE FALSE TRUE TRUE FALSE And why make it difficult? > x %in% letters [1] FALSE TRUE TRUE FALSE TRUE TRUE FALSE No need to make your own function. 回答2:

Is there any value to a Switch / Case implementation in Python?

自古美人都是妖i 提交于 2019-12-07 12:59:38
问题 Recently, I saw some discussions online about how there is no good "switch / case" equivalent in Python. I realize that there are several ways to do something similar - some with lambda, some with dictionaries. There have been other StackOverflow discussions about the alternatives. There were even two PEPs (PEP 0275 and PEP 3103) discussing (and rejecting) the integration of switch / case into the language. I came up with what I think is an elegant way to do switch / case. It ends up looking

Create a Summary View in MySQL by pivoting row into dynamic number of columns

一世执手 提交于 2019-12-07 10:45:06
问题 I have a table in MySQL with the following fields: id, company_name, year, state There are multiple rows for the same customer and year, here is an example of the data: id | company_name | year | state ---------------------------------------- 1 | companyA | 2008 | 1 2 | companyB | 2009 | 2 3 | companyC | 2010 | 3 4 | companyB | 2009 | 1 5 | companyC | NULL | 3 I am trying to create a view from this table to show one company per row (i.e. GROUP BY pubco_name) where the state is the highest for

CASE performance in MySQL?

浪尽此生 提交于 2019-12-07 06:10:49
问题 I wonder if using CASE ... WHEN ... THEN expression in MySQL queries has negative effect on performance? Instead of using CASE expression (for example inside your UPDATE query) you always have possibility to make if else statement in your program written in php, python, perl, java, ... to choose wich query to send, for example (in pseudocode): prepareStatement( "UPDATE t1 SET c1=c1+1, msg=CASE (@v:=?) WHEN '' THEN msg ELSE @v END" ); setStatementParameter(1, message); or insead: if (message =

Erlang : nested cases

怎甘沉沦 提交于 2019-12-07 04:26:36
问题 I'm very new to Erlang. I tried to find out if a list index is out of bounds (before trying it) so i wanted to do an if clause with something like if lists:flatlength(A) < DestinationIndex .... I discovered that those function results cannot be used in if guards so i used case instead. This results in a nested case statement case Destination < 1 of true -> {ok,NumberOfJumps+1}; false -> case lists:flatlength(A) < Destination of true -> doSomething; false -> case lists:member(Destination

Ruby `when' keyword does not use == in case statement. What does it use?

对着背影说爱祢 提交于 2019-12-07 00:53:53
问题 x == User returns true , but case x statement does not run the block associated with User . What's happening here? u = User.new # => #<User:0x00000100a1e948> x = u.class # => User x == User # => true case x when User puts "constant" when "User" puts "string" else puts "nothing?" end # => nothing? 回答1: Case comparisons use === rather than == . For many objects the behaviour of === and == is the same, see Numeric and String : 5 == 5 #=> true 5 === 5 #=> true "hello" == "hello" #=> true "hello"

Ruby: passing array items into a case statement

喜夏-厌秋 提交于 2019-12-06 21:09:29
I am attempting to pass an array into a case statement so I can read the array elements as commands. Unfortunately, it seems that it is not working and the program jumps to the else statement. def input_console() quit = 0 puts "Tell me what you want to do:" loop do print "\n >>> " input = gets.chomp sentence = input.split case sentence when sentence[0] == "go" && sentence[1] == "to" puts sentence[2] when sentence[0] == "quit" quit = 1 else puts "No le entiendo Senor..." end break if quit == 1 end end This piece of code returns "No le entiendo Senor..." whatever you introduce. I expected to get

Nested CASE statements in MySQL

冷暖自知 提交于 2019-12-06 17:14:32
问题 My first time working with CASE Logic in SQL statements. Everything works if I remove the CASE statements, so the SQL is valid without it. I need to calculate the total item price based on a couple of things. If "Sales Price" is active AND "Option Upcharge" has a value, the total is: Qty * (Sales Price + Option Upcharge) If "Sales Price is inactive AND "Option Upcharge" has a value, the total is: Qty * (Price + Option Upcharge) If "Sales Price" is active AND "Option Upcharge" has NO value,

Why are Clojure's multimethods better than 'if' or 'case' statements

99封情书 提交于 2019-12-06 17:10:51
问题 I've spent some time, trying to understand Clojure multimethods. The main "pro" multimethod argument, as far as I understand, is their flexibility, however, I'm confused with the argumentation of why multimethods are better than a simple if or case statement. Could someone, please, explain, where is the line between polymorphism and an overglorified case statement drawn? EDIT: I should have been clearer in the question, that I'm more interested in comparison with the 'if' statement. Thanks a