ERROR: CASE types character varying and numeric cannot be matched

All the branches of a case expression should return the same datatype. One way to achieve that is to explicitly cast where needed: ,(case when all_loc.country = ‘DE’ then msc_si.buyer_id::varchar else msc_si.buyer_name end) as “purchasing_group_name_buyer_name” — Here ———————————————–^ ,(case when all_loc.country = ‘DE’ then msc_si.planner_code::varchar else mscp.description end) as “mrp_controller_name” — And here ———————————————–^

SQL use CASE statement in WHERE IN clause

No you can’t use case and in like this. But you can do SELECT * FROM Product P WHERE @Status=”published” and P.Status IN (1,3) or @Status=”standby” and P.Status IN (2,5,9,6) or @Status=”deleted” and P.Status IN (4,5,8,10) or P.Status IN (1,3) BTW you can reduce that to SELECT * FROM Product P WHERE @Status=”standby” and P.Status … Read more

Mysql SELECT CASE WHEN something then return field

You are mixing the 2 different CASE syntaxes inappropriately. Use this style (Searched) CASE WHEN u.nnmu =’0′ THEN mu.naziv_mesta WHEN u.nnmu =’1′ THEN m.naziv_mesta ELSE ‘GRESKA’ END as mesto_utovara, Or this style (Simple) CASE u.nnmu WHEN ‘0’ THEN mu.naziv_mesta WHEN ‘1’ THEN m.naziv_mesta ELSE ‘GRESKA’ END as mesto_utovara, Not This (Simple but with boolean search … Read more

Dynamic order direction

You could have two near-identical ORDER BY items, one ASC and one DESC, and extend your CASE statement to make one or other of them always equal a single value: ORDER BY CASE WHEN @OrderDirection = 0 THEN 1 ELSE CASE WHEN @OrderByColumn = ‘AddedDate’ THEN CONVERT(varchar(50), AddedDate) WHEN @OrderByColumn = ‘Visible’ THEN CONVERT(varchar(2), Visible) … Read more

What is a good substitute for a big switch-case?

You can store country-power pairs into a Dictionary<string, int> then just get the score of a particular country by using indexer: var points = new Dictionary<string,int>(); // populate the dictionary… var usa = points[“USA”]; Edit: As suggested in comments you should store the information in external file, for example an xml would be a good … Read more

tech