Here is an SQL Queryand its result. How can I get the First and Last VoucherDate for each LoanID
select distinct TD.LoanID, TI.VoucherDate from dbo.tblTransactionInformation TI
inner Join dbo.tblTransactionDetails TD on TI.TRCode = TD.TRCode
Where TI.CompanyCode='CMP-007'
and TI.FyrCode='Fyr-014'
and TI.VoucherDate between '01 - Jul - 2011' and '30-Jun-2012'
and (TI.StateStatus='Approved' or TI.StateStatus ='Checked')
And TD.AccountCode='ACC-000577'
Group by TD.LoanID, TI.VoucherDate
0029390026095 2011-08-08 00:00:00.000
0029390026095 2011-10-23 00:00:00.000
0029390026095 2011-10-31 00:00:00.000
0029390026095 2011-11-20 00:00:00.000
0029390026095 2011-12-05 00:00:00.000
0029390026095 2011-12-28 00:00:00.000
0029390026095 2012-02-15 00:00:00.000
0029390026185 2011-08-25 00:00:00.000
0029390026185 2011-11-20 00:00:00.000
0029390026185 2011-12-02 00:00:00.000
0029390026185 2011-12-22 00:00:00.000
0029390026185 2012-02-15 00:00:00.000
0029390026185 2012-03-07 00:00:00.000
0029390026185 2012-03-22 00:00:00.000
0029390026185 2012-03-28 00:00:00.000
0029390026383 2011-10-31 00:00:00.000
0029390026383 2012-01-24 00:00:00.000
0029390026383 2012-02-15 00:00:00.000
0029390026383 2012-02-29 00:00:00.000
0029390026383 2012-03-07 00:00:00.000
0029390026383 2012-03-13 00:00:00.000
0029390026383 2012-03-22 00:00:00.000
0029390026383 2012-03-28 00:00:00.000
0029390026383 2012-04-08 00:00:00.000
0029390026383 2012-04-16 00:00:00.000
0029390026392 2011-10-31 00:00:00.000
0029390026392 2011-12-28 00:00:00.000
0029390026392 2012-01-24 00:00:00.000
0029390026392 2012-02-06 00:00:00.000
0029390026392 2012-02-29 00:00:00.000
0029390026392 2012-03-13 00:00:00.000
0029390026392 2012-03-28 00:00:00.000
0029390026392 2012-04-16 00:00:00.000
0029390026401 2011-10-31 00:00:00.000
0029390026401 2012-01-18 00:00:00.000
0029390026401 2012-03-07 00:00:00.000
0029390026401 2012-03-13 00:00:00.000
0029390026401 2012-03-28 00:00:00.000
0029390026401 2012-04-16 00:00:00.000
0029390026401 2012-05-16 00:00:00.000
0029390026401 2012-05-21 00:00:00.000
0029390026482 2011-12-07 00:00:00.000
0029390026482 2012-02-09 00:00:00.000
0029390026482 2012-02-23 00:00:00.000
0029390026482 2012-04-08 00:00:00.000
0029390026947 2012-03-07 00:00:00.000
0029390026947 2012-04-08 00:00:00.000
0029390026947 2012-05-17 00:00:00.000
0029390026947 2012-05-21 00:00:00.000
0029390026947 2012-06-14 00:00:00.000