case

[Django Templates] How to get 'switch-case' statement functionality in Django templates?

Hi, I found a link to have a 'switch' tag in Django templates, but I was wondering if this can be somehow achieved without it. Using only the stuff which comes with Django? Basically is there other way then using multiple 'if' or 'ifequal' statements? Thanks in advance for any tips/suggestions. ...

SQL CASE STATEMENT in COUNT CLAUSE

I'm trying to get a product's name and its number of sales from two separate tables. My tables look something like this: BOOK Book_ID | Book_Title | Book_Author SOLD Transaction_ID | Book_ID | Customer_ID I can get most of the results I want from the following query SELECT b.Book_Title, COUNT(s.Book_ID) FROM Book b, Sold s W...

In PHP can I get the total number of case statements in a switch statement?

Is there a way to return the total number of (case) instances there are in a switch statement? Something like this: $id = $_GET['id']; switch ($id) { case "item1" : $data = 'something1'; break; case "item2" : $data = 'something2'; break; } echo $data; But the reasoning for it is there are multiple files with these switc...

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

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 f...

isNull(col, '')

How to write queries to do the followings in SubSonic/C#? select isNull(col, someDefaultValue) from table select x = case when (condition) then col1 else col2 end from table ...

Enum & Switch Case

Hi I am using enums converted to a string with a switch but it doesn't work. It gives compilation error: Cannot implicitly convert type 'userControl_commontop.UserType' to 'string' The code is: private void CommonTopChangesnew(string usertype) { switch (usertype.Trim().ToUpper()) { case UserType.NORMAL : hl...

Using || in Case switch in Rails

I have a partial that I want to display in a layout only when certain pages use that layout. I've set @page_title for all my pages and thought I could use something like this: <% case @page_title when "Log in" || "Forgot Your Password" || "Create a New Password" %><%= render :partial => "common/hello-world" -%><% end -%> But, the incl...

How add "or" in case statements?

Hello, This is what I want to do: switch(myvar) { case: 2 or 5: ... break; case: 7 or 12: ... break; ... } I tried with "case: 2 || 5" ,but it didn't work. The purpose is to not write same code for different values. ...

Unable to change the case of a letter in Zsh

The code in my Zsh #!/bin/zsh q=$1 open "http://mathworld.wolfram.com/$q.html" I put the input to the app triangle I get an error at Wolfram, since the first letter must be a big one. How can you change the case for the first letter in the variable q? ...

How can I have lowercase routes in ASP.NET MVC?

How can I have lowercase, plus underscore if possible, routes in ASP.NET MVC? So that I would have /dinners/details/2 call DinnersController.Details(2) and, if possible, /dinners/more_details/2 call DinnersController.MoreDetails(2)? All this while still using patterns like "{controller}/{action}/{id}". ...

SQL Case statement Syntax

I am trying to write a select statement that will select a number of fields including an email field. There are 3 email fields available in this table which can sometimes contains null values. I wan to look at 3 fields; [email address1], [email address2], [email address3] and basically what I want to do is if [email address3] is null t...

Python Case Insensitive Replace

What's the easiest way to do a case-insensitive str.replace in Python? ...

Simplifying (aliasing) T-SQL CASE statements. Any improvement possible?

As you can see, this sucks big time. Any alternative? I've tried using the column alias in the group by clause to no avail. select count(callid) , case when callDuration > 0 and callDuration < 30 then 1 when callDuration >= 30 and callDuration < 60 then 2 when callDuration >= 60 and callDuration < 120 then 3 ...

Why Switch/Case and not If/Else If?

This question in mainly pointed at C/C++, but I guess other languages are relevant as well. I can't understand why is switch/case still being used instead of if/else if. It seems to me much like using goto's, and results in the same sort of messy code, while the same results could be acheived with if/else if's in a much more organized m...

Regex to change to sentence case

I'm using Notepad++ to do some text replacement in a 5453-row language file. The format of the file's rows is: variable.name = Variable Value Over Here, that''s for sure, Really Double apostrophe is intentional. I need to convert the value to sentence case, except for the words "Here" and "Really" which are proper and should remain c...

Modelling the creation of an Actor in a use case diagram

Hi If you believe that a use case flow of events creates an actor, how would you model that? I have a use case that creates a windows service, which (in my mind) is another system with its own set of use cases and actors. At the moment it is not obvious from the use case diagram that an actor gets created as part of the flow of event...

Ruby a clever way to execute a function on a condition

Hey, As a bit of a fun project I'm implementing a Beatnik interpreter in Ruby. If you've never heard of Beatnik it's an esoteric programming language in which operations are specified by the "scrabble score" of the words in the source code. Anyway, the implementation requires a different operation to happen for different scrabble score...

Alternative to MySQL CASE/WHEN?

I'm trying to select some integer values in MySQL. Several of the values are zero, which I want to grab as an empty string, and grab the integer values when available. So I have something like this: SELECT CASE field WHEN 0 THEN '' ELSE field, [repeat for other fields] Is there any way to shorten this in the SQL query? Does MySQL sup...

Using a Oracle subselect to replace a CASE statement

Hy guys, can anybody please help me with a subquery in Oracle database 10g? I need to extract the values for a column in the first table as value of another column in the second table. I currently use this statement: SELECT CASE WHEN A.column1 = 'A' THEN 'aaa' WHEN A.column1 = 'B' THEN 'bbb' ....... WHEN A.column1 = 'X' THEN 'xxx' ELS...

final public static ints can't be used in a switch statement?!

I'm confused. The following code has errors ("..." represents elided code): int byteOrder = ...; switch (byteOrder) { case HDF5Constants.H5T_ORDER_BE: return ByteOrder.BIG_ENDIAN; ... } The error is on the case statement and Eclipse complains "case expressions must be constant expressions". I looked in the source file ...