I see what you are saying but not sure how to fix it. Suggestions?
You could cast getDate() as a date to get rid of the time component. There are some answers in this thread about selecting the top 5. They are missing an order by clause. I'll leave you to figure that out.
You could cast getDate() as a date to get rid of the time component. There are some answers in this thread about selecting the top 5. They are missing an order by clause. I'll leave you to figure that out.
I think I've got the top figured out but cannot cast to date in SQL CE - datetime works but that defeats the purpose. What is the SQL CE method for casting to date?
SELECT TOP 10 * FROM Events WHERE CAST(StartDate AS Datetime) >= CAST(GETDATE() AS DateTime) ORDER BY StartDate
davidsa
Member
210 Points
126 Posts
Limit the rows returned in sql query
Dec 30, 2012 12:32 AM|LINK
How do you limit the number of rows returned a sql query say to 5 in SQL CE?
Here's my query so far:
Also, in my query it returns events in the future but not for today. What am I missing?
Anil Srivast...
Member
442 Points
292 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 02:06 AM|LINK
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 02:27 AM|LINK
You are not taking the time component of GetDate() into account.
davidsa
Member
210 Points
126 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 02:40 AM|LINK
I tried top 5 before posting but that only returns the first 5 rows in the table. It doesn't check the WHERE condition.
davidsa
Member
210 Points
126 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 02:56 AM|LINK
I see what you are saying but not sure how to fix it. Suggestions?
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 03:03 AM|LINK
You could cast getDate() as a date to get rid of the time component. There are some answers in this thread about selecting the top 5. They are missing an order by clause. I'll leave you to figure that out.
davidsa
Member
210 Points
126 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 04:12 AM|LINK
I think I've got the top figured out but cannot cast to date in SQL CE - datetime works but that defeats the purpose. What is the SQL CE method for casting to date?
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 08:02 AM|LINK
The SELECT query will have a TOP 5 statement. Or else you can use max(Time) as Time in your query. But max(Time) will give you only one result.
So using top 5 willl be good.
var result = Database.Open("Your_Database").Query(query, DateTime.Now);~~! FIREWALL !~~
GmGregori
Contributor
5470 Points
737 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 09:34 AM|LINK
Cast to integer
davidsa
Member
210 Points
126 Posts
Re: Limit the rows returned in sql query
Dec 30, 2012 10:50 PM|LINK
How would date be seperated by casting to an integer?