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

Convert string to Pascal Case (aka UpperCamelCase) in Javascript

s = s.replace(/(\w)(\w*)/g, function(g0,g1,g2){return g1.toUpperCase() + g2.toLowerCase();}); The regex finds words (here defined using \w – alphanumerics and underscores), and separates them to two groups – first letter and rest of the word. It then uses a function as a callback to set the proper case. Example: http://jsbin.com/uvase Alternately, this will also work – a … Read more

Case Expression vs Case Statement

The CASE expression evaluates to a value, i.e. it is used to evaluate to one of a set of results, based on some condition. Example: SELECT CASE WHEN type = 1 THEN ‘foo’ WHEN type = 2 THEN ‘bar’ ELSE ‘baz’ END AS name_for_numeric_type FROM sometable` The CASE statement executes one of a set of … Read more