order-by

ASP.NET MVC - Model.OrderBy Date has no effect

Hello, I'm having some difficulties to sort my results by Date. Is there any special method? Because I'm doing this right now: var db = new DB(); var articles = db.Articles; var orderedArticles = articles.OrderBy(a => a.Date); return View(orderedArticles.ToList()); Where Date is a datetime field. And there is no effect for OrderBy(..)...

Does the Order By clause recalculate the value in SQL Server?

When I use a calculation or a subquery in my ORDER clause which is already in my SELECT clause, does SQL know to just order by that column? Or does it recalculate everything for each row when sorting? For instance, lets say I'm writing a terrible query like this: SELECT EmployeeName, (SELECT COUNT(*) FROM Employee e2 WHERE MgrID = Empl...

I want to show records from a table having a date column from sqldatabase in dates order. How should I?

I want to show records from a table having a date column from sqldatabase in dates order. How should I? ...

SQL ORDER BY date problem

Can you please help me in solving this problem. I am trying to order the results of an SQL query by date, but I'm not getting the results I need. The query I'm using is: SELECT date FROM tbemp ORDER BY date ASC Results are: 01/02/2009 03/01/2009 04/06/2009 05/03/2009 06/12/2008 07/02/2009 Results should be: 06/12/2008 03/01/2009 ...

LINQ to SQL lambda exp. OrderBy, Case When

Hi guys! Going to need your help on this one. I'm trying to OrderBy first reply datetime if present. If it's empty/null, it must order by topic datetime. I've ended up with the following expression, but it just doesn't seem to work :( return db.Topics .Where(t => t.ForumID == id) .OrderBy( t => t.Replies .OrderBy(r => r.AddDat...

Reverse order of bars in a Flex BarChart

I'm trying to use a BarChart in Flex. I'd like it to order the bars according to the order of the ArrayCollection I fed it. i.e. data at index 0 should be the first bar on top. However, Flex is giving me the exact reverse order. i.e. data at index 0 is not the last bar in bottom. How could I tell the BarChart to reverse the order other...

Ordering in a MySQL GROUP_CONCAT with a function in it

I want to order the results in a GROUP_CONCAT function. The problem is, that the selection in the GROUP_CONCAT-function is another function, like this (fantasy select): SELECT a.name, GROUP_CONCAT(DISTINCT CONCAT_WS(':', b.id, c.name) ORDER BY b.id ASC) AS course FROM people a, stuff b, courses c GROUP BY a.id I want to get a resu...

SQL Order By and "Not-So-Much Group"

Hello, Lets say I have a table: -------------------------------------- | ID | DATE | GROUP | RESULT | -------------------------------------- | 1 | 01/06 | Group1 | 12345 | | 2 | 01/05 | Group2 | 54321 | | 3 | 01/04 | Group1 | 11111 | -------------------------------------- I want to order the result by t...

How to use isnull type decision in linqdatasource orderby ?

I have a sql stored procedure that uses isnull in the order by clause to order items by the latest reply date, or if that is null, by the posting date: Example: ORDER BY isnull(rtb.LatestReplyDate,CB_TOPIC_DATE_POSTED) DESC I am trying to get that to work in the orderby clause of a linqdatasource, to no avail yet: Example: ...

PostgreSQL SELECT the last order per customer per date range

In PostgreSQL: I have a Table that has 3 columns: CustomerNum, OrderNum, OrderDate. There may(or may not) be many orders for each customer per date range. What I am needing is the last OrderNum for each Customer that lies in the date range that is supplied. What I have been doing is getting a ResultSet of the customers and querying ...

Django ORM - select_related and order_by with foreign keys

I have a simple music schema: Artist, Release, Track, and Song. The first 3 are all logical constructs while the fourth (Song) is a specific instance of an (Artist, Release, Track) as an mp3, wav, ogg, whatever. I am having trouble generating an ordered list of the Songs in the database. The catch is that both Track and Release have a...

C# List<T> OrderBy always returning null...

Here's my setup. public class ItemList : List<Item> { public void Load() {...} public void Save() {...} } Load reads from an XML file to populate the ItemList I then attempt to order the item list by a Priority. This is an int? For the test purposes however all the items have a different value. ItemList itemList = new ItemList...

SQL Conversion failed Error

WhenI call this stored procedure: ALTER PROCEDURE [dbo].[GetSorted] ( @OrderByColumn nvarchar(256) ) AS SET NOCOUNT ON SELECT itDocs.AddedDate, itDocs.AddedBy FROM itDocs ORDER BY CASE WHEN @OrderByColumn='AddedDate' THEN itDocs.AddedDate WHEN @OrderByColumn='AddedBy' THEN itDocs.A...

nHibernate order by N with SQL Server

With a SQL Query I can order by N, where N is a column index. For example SELECT name, salary FROM employee ORDER BY 2; How can I do this with nHibernate? ...

Linq to Entities Include and Ordery By

I'm using the query below: public IEnumerable<QUESTIONARIO_BASE> ListQuestionario() { var query = (from c in _entities.QUESTIONARIO_BASESet .Include("QUESTAO_BASE") .Include("QUESTAO_BASE.DIMENSAO") .Include("QUESTAO_BASE.RESPOSTA_BASE") ...

Order by in mysql using second table

Hi, I have two tables, one is a list os stores and attributes, the second is a list of allocationsa based on these attributes. The attribute table (stores_metadata) | key | store_key | field | value | 1 | 1 | size | Large | 2 | 1 | dist | Midlands | 3 | 2 | size | Medium | 4 | 3 | dist | Sout...

Problem using OrderBy with the entity framework and ObjectContext.CreateQuery(T)

Hi, I'm having troubles using this method: public ObjectQuery<E> DoQuery(string columnName, int maximumRows, int startRowIndex) { var result = (ObjectQuery<E>)_ctx.CreateQuery<E> ("[" + typeof(E).Name + "]").OrderBy(/*???*/).Skip<E>(startRowIndex).Take(maximumRows); return result; } I'm not sure what needs to go in the ...

Can I Nest OrderBy in .NET?

This doesn't seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ... Next I get this runtime error: Sequence contains no elements There should be 20. Discussions are collections of messages. I w...

Using OrderBy with custom IComparer with SubSonic

I am trying to call OrderBy() using a custom IComparer on a SubSonic IQueryable like so: IQueryable<FooObject> sortedFoos = FooObject.All() .OrderBy(f => f, new FooObjectComparer()); However when I then try to enumerate over sortedFoos or create a PagedList<FooObject> using it, I get a System.Exception: 'The LINQ expression nod...

MySQL ORDER BY optimisation on range

Hello, I'd like MySQL to use the index to sort these rows. SELECT identity_ID FROM identity WHERE identity_modified > 1257140905 ORDER BY identity_modified However, this is using a filesort for sorting (undesirable). Now, if I leave off the ORDER BY clause here, the rows come out sorted simply as a consequence of using the in...