Author |
Topic |
itnagaraj
Yak Posting Veteran
70 Posts |
Posted - 2010-09-21 : 05:39:59
|
Hi All, This is the Data.Number TheNumber Type DatestampIM10134 001A10413 Open 2010-07-19 07:51:43.000IM10134 001A10424 Status Change 2010-08-02 09:45:27.000IM10134 001A10425 External Vendor Assignment 2010-08-02 09:45:27.000IM10134 001A10426 Update 2010-08-02 09:47:49.000 Query isSelect Number,TheNumber,Type,Max(Datestamp) From ACTIVITYM1Where Number = 'IM10134'Group By Number,TheNumber,TypeSo How to Select Maximum datestamp Record only.Kindly help me.V.NAGARAJAN |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-09-21 : 05:42:15
|
Do u need this?Select Max(Datestamp) From ACTIVITYM1Where Number = 'IM10134'Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
itnagaraj
Yak Posting Veteran
70 Posts |
Posted - 2010-09-21 : 05:44:38
|
Hi, I know this query.I want remaining fields also.so how to select.quote: Originally posted by senthil_nagore Do u need this?Select Max(Datestamp) From ACTIVITYM1Where Number = 'IM10134'Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
V.NAGARAJAN |
 |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-09-21 : 05:53:12
|
As shown in your example the TheNumber,Type column are always changing!What your expected output?Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-21 : 06:02:14
|
Is it not just this.......SELECT TOP 1 Number , TheNumber , Type , DatestampFROM ACTIVITYM1WHERE Number = 'IM10134'ORDER BY Datestamp DESC Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
itnagaraj
Yak Posting Veteran
70 Posts |
Posted - 2010-09-21 : 06:05:45
|
it OK for selecting single record only.how to select multiple record in a Table.How it is possible.quote: Originally posted by Transact Charlie Is it not just this.......SELECT TOP 1 Number , TheNumber , Type , DatestampFROM ACTIVITYM1WHERE Number = 'IM10134'ORDER BY Datestamp DESC Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
V.NAGARAJAN |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-21 : 06:09:59
|
I don't understand what you are asking for.Given the data you posted:Number TheNumber Type DatestampIM10134 001A10413 Open 2010-07-19 07:51:43.000IM10134 001A10424 Status Change 2010-08-02 09:45:27.000IM10134 001A10425 External Vendor Assignment 2010-08-02 09:45:27.000IM10134 001A10426 Update 2010-08-02 09:47:49.000 My query produces the line you said you wanted. (the one with the highest datestamp.What do you actually want? Can you show us a dataset and the required output?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
itnagaraj
Yak Posting Veteran
70 Posts |
Posted - 2010-09-21 : 06:20:24
|
This is the dataNumber Number Type DatestampIM10134 001A10413 Open 2010-07-19 07:51:43.000IM10134 001A10424 Status Change 2010-08-02 09:45:27.000IM10134 001A10425 External Vendor 2010-08-02 09:45:27.000IM10134 001A10426 Update 2010-08-02 09:47:49.000IM10135 001A10414 Open 2010-07-20 09:00:51.000IM10136 001A10415 Open 2010-07-20 09:28:04.000IM10136 001A10429 Resolved 2010-08-02 11:25:19.000IM10137 001A10416 Open 2010-07-20 09:38:23.000IM10138 001A10417 Open 2010-07-20 09:44:12.000IM10138 001A10427 Resolved 2010-08-02 11:20:56.000IM10138 001A10428 Closed 2010-08-02 11:21:48.000IM10139 001A10418 Open 2010-07-22 15:18:19.000I want the folloowing result set.Number TheNumber Type DatestampIM10134 001A10426 Update 2010-08-02 09:47:49.000IM10135 001A10414 Open 2010-07-20 09:00:51.000IM10136 001A10429 Resolved 2010-08-02 11:25:19.000IM10137 001A10416 Open 2010-07-20 09:38:23.000IM10138 001A10428 Closed 2010-08-02 11:21:48.000IM10139 001A10418 Open 2010-07-22 15:18:19.000How make a queryquote: Originally posted by Transact Charlie I don't understand what you are asking for.Given the data you posted:Number TheNumber Type DatestampIM10134 001A10413 Open 2010-07-19 07:51:43.000IM10134 001A10424 Status Change 2010-08-02 09:45:27.000IM10134 001A10425 External Vendor Assignment 2010-08-02 09:45:27.000IM10134 001A10426 Update 2010-08-02 09:47:49.000 My query produces the line you said you wanted. (the one with the highest datestamp.What do you actually want? Can you show us a dataset and the required output?Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
V.NAGARAJAN |
 |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-09-21 : 06:39:55
|
Try thisSelect * from (select row_number() over(partition by Number order by Datestamp desc)as s_no ,* from table_name) a where s_no=1Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2010-09-21 : 07:08:01
|
Or if you don't want the ranking columnsSELECT dt.[Number] , dt.[TheNumber] , dt.[Type] , dt.[Datestamp]FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY [Number] ORDER BY [Datestamp] ) AS [rowPos] , [Number] AS [Number] , [TheNumber] AS [TheNumber] , [Type] AS [Type] , [Datestamp] AS [Datestamp] FROM <<TABLE_NAME>> ) AS dtWHERE dt.[rowPos] = 1 Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|