Solved

sql order

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…

821 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