Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

cant select records with where clause

Posted on 2008-10-06
6
Medium Priority
?
209 Views
Last Modified: 2012-05-05
I cant select records based on a where clause and row limit.
I want the first 5 rows with where clause from1='x'. What happens is that this checks rows 1 and 5 and from that selects any that have from1='x'. so i could have 0 to 5 only .




command.CommandText = "  SELECT * FROM (  SELECT email.* " & _
      " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
      " FROM email) sq WHERE RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & " and to1='x'"

Open in new window

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
  • 3
  • 2
6 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 22648479
have you tried to set your where clause in the inner query:

command.CommandText = "  SELECT * FROM (  SELECT email.* " & _
      " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
      " FROM email WHERE from1='x') sq WHERE RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & " and to1='x'"
0
 
LVL 8

Expert Comment

by:mikainz
ID: 22648483

Try
WHERE (RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & ") and to1='x'"
0
 

Author Comment

by:jagguy
ID: 22648487
sorry this is the code

 command.CommandText = "  SELECT * FROM (  SELECT email.* " & _
         " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
         " FROM email) sq WHERE RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & " and from1='" & from1 & "'"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Accepted Solution

by:
mikainz earned 2000 total points
ID: 22648497
I think you need brackets
WHERE (RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & ") and from1='" & from1 & "'"
0
 

Author Comment

by:jagguy
ID: 22648503
ok this works


command.CommandText = "  SELECT * FROM (  SELECT email.* " & _
      " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
      " FROM email WHERE from1='x') sq WHERE RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & " and to1='x'

 WHERE (RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage & ") and to1='x'"
and this doesnt?
0
 

Author Comment

by:jagguy
ID: 22648516
this is best option

 command.CommandText = "  SELECT * FROM (  SELECT email.* " & _
          " , ROW_NUMBER() OVER (ORDER BY id) AS [RowNumber]" & _
          " FROM email WHERE from1='x') sq WHERE RowNumber BETWEEN " & pageNo & " AND " & rowsPerPage
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

609 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