Solved

sql order

Posted on 2011-03-11
2
296 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
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now