case-when

Mysql CASE - WHEN - THEN - returning wrong data type (blob)

≡放荡痞女 提交于 2019-12-25 08:58:02
问题 Im creating customizable product attributes in a web store - each attribute can have different type of data, each data type is stored in a separate column using corresponding mysql datatype. I Have a query like: SELECT products.id AS id, products.sku AS sku, products.name AS name, products.url_key AS url_key, attributes.name AS attribute, CASE WHEN `attribute_types`.`type` = 'text' THEN product_attribute_values.value_text WHEN `attribute_types`.`type` = 'float' THEN product_attribute_values

LINQ for RANK() and CASE WHEN in VB.NET

自闭症网瘾萝莉.ら 提交于 2019-12-25 08:29:47
问题 I apologize, if a similar question is already asked in VB.Net for the RANK() and CASE WHEN . I have two tables. The script with the required columns are below: Table 1: SELECT S.* INTO dbo.LoanHeader FROM ( SELECT 1 LoanHeaderId, 1234 LoanNumber, GETDATE() EffectiveOn UNION ALL SELECT 2 LoanHeaderId, 2234 LoanNumber, GETDATE() EffectiveOn UNION ALL SELECT 3 LoanHeaderId, 3234 LoanNumber, GETDATE() EffectiveOn )S Table 2: SELECT S.* INTO dbo.LoanHeaderHistory FROM ( SELECT 1 LoanHeaderId, 1

SQL: Nested Condition in Case When Clause

☆樱花仙子☆ 提交于 2019-12-25 03:46:14
问题 I have a Case-When clause like this; (CASE WHEN A.YAZ_ADRES IS NULL THEN (B.IS_ADRES1 +' '+B.IS_ADRES2) ELSE A.YAZ_ADRES END) I want to use a condition after THEN For Example; (CASE WHEN A.YAZ_ADRES IS NULL THEN (IF B.TUZ = 'T' THEN (B.IS_ADRES1 +' '+B.IS_ADRES2) ELSE ((B.EV_ADRES1 +' '+B.EV_ADRES2))) ELSE A.YAZ_ADRES END) How can I use nested condition in Case-When ? 回答1: You can nest CASE clauses like this: (CASE WHEN A.YAZ_ADRES IS NULL THEN (CASE WHEN B.TUZ = 'T' THEN (B.IS_ADRES1 +' '+B

Are both queries the same?

…衆ロ難τιáo~ 提交于 2019-12-23 18:59:34
问题 Are both queries are same ? Do both return the same result ? 1) IF EXISTS( SELECT 1 FROM Users u WHERE u.UPIN = @AttendingDoctorID) BEGIN SELECT u.UserId, 1 FROM Users u WITH(nolock) WHERE u.UPIN = @AttendingDoctorID END ELSE BEGIN SELECT u.UserId, 1 FROM Users u (nolock) WHERE u.FirstName = @AttendingDoctorFirstName AND u.LastName = @AttendingDoctorLastName END 2) SELECT u.UserId, 1 FROM Users u (nolock) WHERE (u.UPIN = @AttendingDoctorID) OR (u.FirstName = @AttendingDoctorFirstName AND u

If-else (nested) or when condition in JSTL

老子叫甜甜 提交于 2019-12-22 12:07:25
问题 I have a program that populates a table and depending on the type of value in each cell, I change the formatting - like percentage, decimal places, grouping etc. I have a table that is the default view and I allow the user to filter those results by entering a document number and the table then changes to add 2 columns - document number and the corresponding document name. So, if the number of columns retrieved is say, 10, then some behaviour. If if it is 12, then, some other behaviour. Date

Using CASE, WHEN, THEN, END in a select query with MySQL

谁说胖子不能爱 提交于 2019-12-22 06:59:56
问题 I'm working on a baseball related website. I have a table with a batting lineup for two baseball teams: +----+----------+--------------+--------+ | id | playerId | battingOrder | active | +----+----------+--------------+--------+ Batting order is an integer between 1 and 20. This corresponds to the following logic: Batting Order 1-9 — Away Team Lineup Batting Order 10 — Away Team Pitcher Batting Order 11-19 — Home Team Lineup Batting Order 20 — Home Team Pitcher The active field is a tinyint

How to show the maximum number for each combination of customer and product in a specific state in Postgresql?

故事扮演 提交于 2019-12-20 06:26:27
问题 I just begin learning Postgresql recently. I have a table named 'sales': create table sales ( cust varchar(20), prod varchar(20), day integer, month integer, year integer, state char(2), quant integer ) insert into sales values ('Bloom', 'Pepsi', 2, 12, 2001, 'NY', 4232); insert into sales values ('Knuth', 'Bread', 23, 5, 2005, 'PA', 4167); insert into sales values ('Emily', 'Pepsi', 22, 1, 2006, 'CT', 4404); insert into sales values ('Emily', 'Fruits', 11, 1, 2000, 'NJ', 4369); insert into

Simplify nested case when statement

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 03:35:33
问题 Below is my current SELECT CASE statement: SELECT CASE WHEN edition = 'STAN' AND has9 = 1 THEN '9' WHEN edition = 'STAN' AND has8 = 1 THEN '8' WHEN edition = 'STAN' AND has7 = 1 THEN '7' WHEN edition = 'STAN' AND hasOLD = 1 THEN 'OLD' WHEN edition = 'SUI' AND has_s9 = 1 THEN 'S9' WHEN edition = 'SUI' AND has_s8 = 1 THEN 'S8' ELSE 'S7' END AS version I do not always want to repeat the edition = 'xxx' condition, such as CASE WHEN edition = 'STAN' AND has9 = 1 THEN '9' ELSE WHEN has8 = 1 THEN '8

How can I Compare two tables without relationship (1 table with 40k records and the other one with 7k records)?

纵饮孤独 提交于 2019-12-13 10:54:59
问题 I tried using Cross Join but it takes 5 minutes to run, there is another way to do that? Note: I'm comparing dates and Int Fields, Table 1 has records from a system and table 2 store a work calendar dates. SQL Server. B FILE C FILE Trying to achieve SampleCode 回答1: You don't make it easy, but here is a working solution. In the future try to use this type of code in your question so we can focus on the query and solution. I have edited some of your dates to make the example work. EDIT : New

Alternative to Case when with subqquery to avoid error (Illegal expression in When clause within case statement)

醉酒当歌 提交于 2019-12-13 03:41:48
问题 My table structure looks similiar to this Customer_id Country item_type Order_Size Dates Codes A401 US Fruit Small 3/14/2016 11 A401 US Fruit Big 5/22/2016 12 A401 US Vegetable Small 7/12/2016 11 B509 US Vegetable Small 3/25/2015 92 B509 US Vegetable Big 3/15/2014 11 B509 US Vegetable Small 3/1/2014 34 A402 CA Fruit Small 3/14/2016 56 A402 CA Fruit Big 5/22/2016 76 A402 CA Fruit Small 7/12/2016 85 A403 CA Vegetable Small 7/12/2016 11 A403 CA Vegetable Small 3/25/2015 16 A403 CA Vegetable Big