case

Java program for calculating fractions

荒凉一梦 提交于 2019-12-04 04:55:12
问题 The purpose of the program is to get two user inputs for a fraction, receive a operator from the user, and then to get two more user inputs for a second fraction. The program must check that the numbers used in both fractions range between 0-99 and have a non-zero denominator. The program also has to make sure that the user inputs a valid operator (-,+,*,/). The only problem I am facing now is that none of my variables are being initialized and that I don't know how to make the output look

Switching from FOR loops in plpgsql to set-based SQL commands

三世轮回 提交于 2019-12-04 04:47:54
问题 I've got quite heavy query with FOR loop to rewrite and would like to do it simpler, using more SQL instead of plpgsql constructions. The query looks like: FOR big_xml IN SELECT unnest(xpath('//TAG1', my_xml)) LOOP str_xml = unnest(xpath('/TAG2/TYPE/text()', big_xml)); FOR single_xml IN SELECT unnest(xpath('/TAG2/single', big_xml)) LOOP CASE str_xml::INT WHEN 1 THEN INSERT INTO tab1(id, xml) VALUES (1, single_xml); WHEN 2 THEN INSERT INTO tab2(id, xml) VALUES (1, single_xml); WHEN 3 [...]

Use “result expression” from CASE expression in WHERE clause

断了今生、忘了曾经 提交于 2019-12-04 04:10:26
问题 Is it possible to filter records in SQL Server by using a result expression (weight_class) from a CASE expression in the WHERE clause? I can't get it to work because I get an error saying: Invalid column name 'weight_class' Code: SELECT first_name, last_name, weight_class = CASE WHEN weight < 172 THEN 'Welterweight' WHEN weight <= 192 THEN 'Middleweight' WHEN weight <= 214 THEN 'Light heavyweight' WHEN weight <= 220 THEN 'Cruiserweight' ELSE 'Heavyweight' END FROM athletes This is how I want

Case insensitivity in selectors?

有些话、适合烂在心里 提交于 2019-12-04 04:02:00
I am trying to use jQuery for XML processing. One of the problem that I am stuck with jQuery is it is case insensitive in processing tags and attribute. For e.g., consider the following code: $("<div><Book ISBN='1234'>Some title</Book></div>").html() the output we get is: <book isbn="1234">Some title</book> whereas the output i am looking for is: <Book ISBN="1234">Some title</Book> Any possibility? (Note that "B" is capital letter, and the whole attribute name "ISBN" is also in capital case, whereas the jQuery html output is completely lower case) Please help. two7s_clash According to http:/

How to choose inner join field with IF/case?

狂风中的少年 提交于 2019-12-04 01:54:20
问题 Bit of a tricky one. I am in the middle of cleaning up some data but because of the size of the data, it's going to take quite a while to do and thus I need the app to run while the upgrade is performing. So, I have a comments table and a photos table. Each comment record has either the photo_d_id stored in object_id or the photo_id stored in object_id : if comment_type = 8 then object_id = photo.photo_p_id if comment_type = 17 then object_id = photo.photo_id I need to inner join the photo

Case when a value is different to other value, SQL Server

可紊 提交于 2019-12-03 22:16:33
I have this table structure for table prices : CREATE TABLE prices ( id int, priceFrom int, priceUp int ); INSERT INTO prices (id, priceFrom, priceUp) VALUES (1, 23, 23), (2, 0, 0), (3, 12, 13), (4, 40, 40), (5, 15, 15), (6, 0, 0); This is the result: I have this query: select pricefrom, priceup, case when pricefrom = 0 then null when priceFrom <> priceUp then priceFrom + ' - ' + priceUp when priceFrom = priceUp then priceFrom end as FinalPrice from prices what I need is to do a case when pricefrom = 0 then show null pricefrom = priceup then show the price At least if pricefrom != priceup I

C# Switch-case string starting with

▼魔方 西西 提交于 2019-12-03 22:02:38
Is there any way to make a case condition in a switch statement where you say if a string begins with something? ex Switch (mystring) { case("abc")://String begins with abc (abcd or abc1 or abcz or abc.. or abc will fall in this condition). //Do Something break; default: break; } UPDATE Other strings can be different length. abc.. abczyv dcs2. qwerty as...k If you knew that the length of conditions you would care about would all be the same length then you could: switch(mystring.substring(0, Math.Min(3, mystring.Length)) { case "abc": //do something break; case "xyz": //do something else break

Add Case Statement in Where Clause

让人想犯罪 __ 提交于 2019-12-03 20:09:57
I need to add a case statement in a where clause. I want it to run either statement below depending on the value of TermDate. Select * from myTable where id = 12345 AND TermDate CASE WHEN NULL THEN AND getdate() BETWEEN StartDate AND DATEADD(dd, 30, StartDate) ELSE AND GETDATE < TermDate END Why not just use an OR condition? SELECT * FROM myTable WHEN id = 12345 AND ((TermDate IS NULL AND getdate() BETWEEN StartDate AND DATEADD(dd, 30, StartDate)) OR GETDATE() < TermDate) Since we all posted three exact answers, obviously too much, here a version that uses your case when construction. use this

Changing case (upper/lower) on adding data through Django admin site

丶灬走出姿态 提交于 2019-12-03 16:25:21
I'm configuring the admin site of my new project, and I have a little doubt on how should I do for, on hitting 'Save' when adding data through the admin site, everything is converted to upper case... Edit: Ok I know the .upper property, and I I did a view, I would know how to do it, but I'm wondering if there is any property available for the field configuration on the admin site :P If your goal is to only have things converted to upper case when saving in the admin section, you'll want to create a form with custom validation to make the case change: class MyArticleAdminForm(forms.ModelForm):

Which things around case classes will be removed after Scala 2.9 exactly?

家住魔仙堡 提交于 2019-12-03 14:39:30
I know that the are some changes planned regarding case classes, like disallowing inheritance between them: scala> case class Foo() defined class Foo scala> case class Bar() extends Foo() <console>:9: warning: case class `class Bar' has case ancestor `class Foo'. Case-to-case inheritance has potentially dangerous bugs which are unlikely to be fixed. You are strongly encouraged to instead use extractors to pattern match on non-leaf nodes. case class Bar() extends Foo() ^ defined class Bar or case classes without parameter list (not sure about that): scala> case class Foo <console>:1: warning: