May 8, 2013 at 8:31 am
Hi Friends,
I have some rows where all the fields are very much similar to each other except date & time field. I need to select top 1 row based on date & time field in descending order. I used row number method to achieve this. But i just want to know if there is any other better way. Since i am dealing with millions of data so i am facing performance issue as well as tempdb drastically increasing. Any suggestions would be really appreciated.
I have attached a screen shot of the sceneraio.
Friends, let me know if you need DDL and DML also.
May 8, 2013 at 8:37 am
prakashr.r7 (5/8/2013)
Hi Friends,I have some rows where all the fields are very much similar to each other except date & time field. I need to select top 1 row based on date & time field in descending order. I used row number method to achieve this. But i just want to know if there is any other better way. Since i am dealing with millions of data so i am facing performance issue as well as tempdb drastically increasing. Any suggestions would be really appreciated.
I have attached a screen shot of the sceneraio.
Friends, let me know if you need DDL and DML also.
There very well might be a better way. However you didn't post anywhere near enough information for us to help. We can't really offer much based on a screen shot of results from a query. I would start with posting the actual execution plan from your query. That will provide some insight on what is going on. Then before we can really help with code, we would need to see ddl (create table scripts, and indexes), sample data (insert statements), the desired output and the code you are currently using.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 8, 2013 at 8:54 am
Yeah, no real way to tell you how to improve a query without seeing that query. Imagine I said my car wasn't running well and asked you to fix it... from where you're sitting.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply