DECLARE @Today DATETIME
set @Today = CONVERT(datetime,Convert(Char(10), GetDate(),20),20)
select I.booking_no_v32 as [Booking Number] ,
I.product_code_v42 AS [Product Code],
I.trans_qty AS [Qty Ordered],
ISNULL((select I.trans_qty - sum(T.qtycheckedOut) from tblAssetran T where I.SubRentalLinkID = T.ItemTranID and I.booking_no_v32 = T.booking_no),I.trans_qty) [Pending Check out],
ISNULL((select sum(qtycheckedout) - sum(t.Qtyreturned) from tblAssetran t where I.SubRentalLinkID = t.ItemTranID and I.booking_no_v32 = t.booking_no),0) [Pending Return]
FROM tblItemtran I where (isnull(i.product_code_v42,'') <> '')
and i.booking_no_v32 in (select top 1 booking_no from tblAssetran where ActOutDate >= @Today)
and i.trans_type_v41 = 11
ORDER BY I.booking_no_v32