Solved

sql order

Posted on 2011-03-11
2
305 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:Rahul Agarwal
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

636 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