Saturday, June 29, 2013

Query help

Hi Kapil,


You will not get trans2 because you do not have a value "Trans2" for TransNo in the table T1.


I have tired this query which give exact result what you want by changing the last insert value from trans1 to trans2.



Create table T1
(Id int identity primary key,
VoucherNo varchar(10),
TransNo varchar(10)
)

Insert into T1 values ('V100','Trns1'),('V101','Trns1'),('V102','Trns1'),('V103','Trns1'),('V104','Trns1'),('V106','Trns2')

SELECT TransNo,
MIN(VoucherNo) AS FirsvoucherNo,
MAX(VoucherNo) AS LastVoucherNo,
COUNT(VoucherNo) AS Quantity
FROM T1
GROUP BY TransNo





Regards Harsh


No comments:

Post a Comment