Solved

sql order

Posted on 2011-03-11
2
300 Views
Last Modified: 2012-06-27
q) I am using vb.net to access  a sql server DB. It works but I want the data ordered by a date field.
Also is there an easier way to display data from a given range . The below code is messy but it works.



 command.CommandText = "  SELECT * FROM (  SELECT thread.* " & _
  " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
  " FROM thread) sq WHERE RowNumber BETWEEN " & LPage & " AND " & UPage
0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 35114790
ROW_NUMBER() assigns serial number based on the ORDER of a column
In your code, it seems to be order by 'ID' column
So try change
ORDER BY id

Open in new window

to
ORDER BY YourDateColumn

Open in new window

in that query
Raj
0
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35115544
Try this Code:

command.CommandText = "  SELECT * FROM (  SELECT thread.* " & _
  " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
  " FROM thread ) sq WHERE RowNumber BETWEEN " & LPage & " AND " & UPage order by DateColumn
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question