Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql order

Posted on 2011-03-11
2
Medium Priority
?
311 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

730 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