case

BEGIN…END block in SQL Server

人盡茶涼 提交于 2019-12-12 03:37:33
问题 Are there any rules defined for grouping the T-SQL statements under the BEGIN...END block ? Because when I try the BEGIN...END block inside the CASE statement OR IIF statement, it fails. I need BEGIN...END block because there are multiple operations that I want to perform under the CASE result. SELECT CASE @ChargePaid WHEN 1 THEN BEGIN SELECT 'Paid' END WHEN 0 THEN BEGIN SELECT 'Not Paid' END END OR SELECT IIF( @ChargePaid > 0, BEGIN SELECT 'Paid' END , BEGIN SELECT 'Not Paid' END ) EDIT: IF

What does it happen when using multiple CASE … WHEN statements in the same SQL query?

梦想的初衷 提交于 2019-12-12 03:35:18
问题 After my previous question, I have an SQL query like the following: SELECT * WHERE ... ORDER BY CASE user_id WHEN 34 THEN 1 ELSE 2 END, CASE status WHEN 'active' THEN 1 ELSE 2 END As you can see in the above code, there are two CASE ... WHEN statements. What happens in this case? That is, how records will be ordered? May those "doubled" statements conflict? UPDATE : I would like to make it to return records in this order: (1) records where user_id = 34 and status = 'active' ; (2) records

sql to LINQ that has a CASE and a sub query

只谈情不闲聊 提交于 2019-12-12 03:07:32
问题 I have been strugging to convert the query below to a linq query, im pretty close but I am not sure how to add in a case statement to LINQ. Googling around got me this close. Original Working Query: SELECT *, CASE WHEN Recipe_Name IN (SELECT Recipe_Name FROM Recipes WHERE Status = 2) THEN 0 ELSE 1 END AS editable FROM Recipes WHERE Status = 1 ORDER BY Recipe_Name; My LINQ - Missing the case statement: var lcrecipes = from r in db.Recipes where r.Status == 2 select r.Recipe_Name; var

Avoiding repetitive conditions in the select case and where clause

社会主义新天地 提交于 2019-12-11 23:37:35
问题 I have a table say TAB1 with the following columns - USER_ID NUMBER(5), PHN_NO1 CHAR(20), PHN_NO2 CHAR(20) I have to fetch records from TAB1 into another table TAB2 such that all records with either one of the two or both PHN_NO1 and PHN_NO2 are of length 10 and begin with 5. If in a record,say only PHN_NO1 satisfies the condition and PHN_NO2 does not then, TAB2.P1 should be same as TAB1.PHN_NO1 but TAB2.P2 should be NULL. If neither of the two satisfy the condition, then the record should

How to use CASE to get 3 columns from a single column?

佐手、 提交于 2019-12-11 23:27:24
问题 I have one table "DataDollar"...and 2 columns "LineNmbr" & "DollarAmt" in that. I need to display this column values as in three columns depending upon their values. Please help me ! SELECT DollarAmt AS CASE LineNmbr WHEN 19 THEN 'A-Amt' WHEN 20 THEN 'P-Amt' ELSE 'D-Amt' END FROM DataDollar 回答1: Try using three case expressions, one for each column in the result set: SELECT CASE LineNumber WHEN 19 THEN DollarAmt END AS AAmt, CASE LineNumber WHEN 20 THEN DollarAmt END AS PAmt, CASE WHEN

Is it possible for WHEN to check the if the variable belongs to an array?

*爱你&永不变心* 提交于 2019-12-11 22:48:54
问题 How can I do something like this ? or do i need to use IF all the time? ar = [["a","b"],["c"],["d","e"]] x = "b" case x when ar[0].include?(x) puts "do something" when ar[1].include?(x) puts "do else" when ar[2].include?(x) puts "do a 3rd thing" end I'm using ruby 1.8.7 回答1: It's not only possible, it's easy. For constant arrays: #!/usr/bin/ruby1.8 x = "a" case x when 'a', 'b' puts "do something" # => do something when 'c' puts "do else" when 'd', 'e' puts "do a 3rd thing" end Or, if the

Case statement in oracle with comparision in Then clause

冷暖自知 提交于 2019-12-11 21:26:17
问题 I am new to using Oracle trying something similar to below code, but unable to accomplish the task. CASE WHEN Dimension='abc' then value=100 When Dimension='def' then Value between 200 and 300 end but it is throwing error Missing Keyword state Please help me to solve this issue 回答1: You can rewrite your where clause this way. (Dimension='abc' and value=100) or (Dimension='def' and value between 200 and 300) 来源: https://stackoverflow.com/questions/19534054/case-statement-in-oracle-with

Collate language codes into one combined locale code using CASE WHEN, and count the number of times the combined locale code occurs on a date

China☆狼群 提交于 2019-12-11 21:21:12
问题 Learning about CASE WHEN, and I've come across a use case when I see multiple locale codes in Analytics. This is a much simpler question that is much easier to answer and read, than my prior question that was posted. Examples are: en-us (english US) en-au (english australia) en-br (english brazil) es-es (spanish spain) es-419 (spanish-latam) pt-br (portuguese brazil) pt-pt (portugal) How do I aggregate these in BigQuery so that instead of counting distinct values, I can count the number of

SQL Server - Setting Multiple Values in a Case Statement?

心已入冬 提交于 2019-12-11 20:44:04
问题 I have a SQL Select statement where I need to return certain values depending on a condition. I need to return multiple values each time, but my understanding of the Case statement is that you can only return a single value for each case. I'm getting around this by using UNION statements at the moment, but it all looks a bit cumbersome - is there a better way to do this? Basically, I have a bunch of prompts, each with a response of either "Yes", "No" or "In Future" (I actually have more

How to get the looop equivalent command in teradata

筅森魡賤 提交于 2019-12-11 20:00:34
问题 I am very new to Teradata. Here I dont see any looping command to execute the following-- Input Structure A B C -- -- -- 1 b c 1 d d 1 c d 1 fx b Output_Structure-- A B C -- -- -- 1 fx b 1 b c 1 c d 1 d d here if we implement with the CASE structure it will work, like CASE IF (B ='fx' THEN SELECT C AS A1) CASE IF(B!= 'fx' THEN SELECT C WHERE B=A1) but if the number of records are more then we need to implement through LOOP. So any suggestion on this. 回答1: This looks like a hierarchy, you need