| Author |
Topic |
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2007-02-10 : 01:12:19
|
| Respected Friends,kindly solve my query.Table Structrue:Table Name : Custom_Table_SPPR_Master Fields :Sno int pkSPPR_No int pkRevison_No int pkrev_Date dateprop_amt decimalclaim_amt decimalavail_amt decimalStatus intDataSno SPPR_No Revison_No rev_Date prop_amtclaim_amtavail_amtStatus 1 2000 0 2006-10-01 00:00:00.000 1000 600 400 22 2000 1 2006-10-01 00:00:00.000 1100 600 500 23 2000 2 2006-10-01 00:00:00.000 1400 600 800 24 2000 3 2006-10-01 00:00:00.000 1500 900 600 25 2001 0 2006-10-01 00:00:00.000 1000 200 800 26 2001 1 2006-10-01 00:00:00.000 1200 600 600 27 2002 0 2006-10-01 00:00:00.000 1000 600 400 28 2002 1 2006-10-01 00:00:00.000 1100 600 500 29 2003 0 2006-10-01 00:00:00.000 1000 600 400 2I want the record where max of the revision no is seen for each spprthat is the result should the rows of sno: 4,6,8,9i tried the following but in veinselect max(revision_no) ,sppr_no from Custom_Table_SPPR_Master group by sppr_no-- in this i am getting records, but i want * datasselect distinct(sppr_no) from Custom_Table_SPPR_Master where revision_no in(select max(revision_no) from Custom_Table_SPPR_Master group by revision_no) group by sppr_noselect sppr_no,count(revision_no) from Custom_Table_SPPR_Master where revision_no in(select max(revision_no) from Custom_Table_SPPR_Master group by revision_no)group by sppr_no,revision_noKindly let me the answers . thanks in advance. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-10 : 02:22:29
|
[code]declare @Custom_Table_SPPR_Master table( Sno int, SPPR_No int, Revison_No int, rev_Date datetime, prop_amt int, claim_amt int, avail_amt int, Status int)insert into @Custom_Table_SPPR_Master select 1, 2000, 0, '2006-10-01', 1000, 600, 400, 2 union allselect 2, 2000, 1, '2006-10-01', 1100, 600, 500, 2 union allselect 3, 2000, 2, '2006-10-01', 1400, 600, 800, 2 union allselect 4, 2000, 3, '2006-10-01', 1500, 900, 600, 2 union allselect 5, 2001, 0, '2006-10-01', 1000, 200, 800, 2 union allselect 6, 2001, 1, '2006-10-01', 1200, 600, 600, 2 union allselect 7, 2002, 0, '2006-10-01', 1000, 600, 400, 2 union allselect 8, 2002, 1, '2006-10-01', 1100, 600, 500, 2 union allselect 9, 2003, 0, '2006-10-01', 1000, 600, 400, 2select *from @Custom_Table_SPPR_Master tinner join( select SPPR_No, Revison_No = max(Revison_No) from @Custom_Table_SPPR_Master t group by SPPR_No) mon t.SPPR_No = m.SPPR_Noand t.Revison_No = m.Revison_Noorder by Sno[/code] KH |
 |
|
|
shanmugaraj
Posting Yak Master
219 Posts |
Posted - 2007-02-10 : 03:53:26
|
| Thanks a Lot khtan. i have got the result. |
 |
|
|
|
|
|