June 14, 2011 at 8:04 am
Can any one help me how to get next greatest date for same id.
for example if a member has 3 order_dates
id order_dates
100 2008-03-31
100 2008-04-16
100 2008-10-08
then I want result as
id min_order_dates max_order_dates
100 2008-03-31 2008-04-16
100 2008-04-16 2008-10-08
Any help would be appreciated
June 14, 2011 at 8:08 am
Take a look at the top expression and order.
_______________________________________________________________
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/
June 14, 2011 at 8:10 am
Please don't post the same question again. Please direct all replies to the original thread
_______________________________________________________________
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/
June 14, 2011 at 8:21 am
Sorry for not giving more details.Hope this will help you to help me what I am looking for.Thank you.
CREATE TABLE
#mytable
(
ID INT PRIMARY KEY CLUSTERED,
order_date DATETIME )
Insert into #mytable
values (100 ,2008-03-31) ,
(100 ,2008-04-16 ),
(100 ,2008-10-08 )
I’m trying to get the next biggest date for a record with the same id
for example
id max_order_date order_date
100 2008-04-16 2008-03-31
100 2008-10-08 2008-04-16
June 14, 2011 at 8:29 am
Like I said you already posted this question and you got an answer. In fact, I gave you pretty much the same answer.
_______________________________________________________________
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/
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply