You can write DF to get comma separated values...CREATE FUNCTION CombineValues( @Item_ID varchar(5)-- The foreign key from TableA which is used -- to fetch corresponding records)RETURNS VARCHAR(8000)ASBEGINDECLARE @SomeColumnList VARCHAR(8000);SELECT @SomeColumnList = COALESCE(@SomeColumnList + ', ', '') + CAST(InvID AS varchar(20)) FROM tblinvoice CWHERE C.ItemID = @Item_ID;RETURN ( SELECT @SomeColumnList)ENDSELECT ItemID, dbo.CombineValues(ItemID), SUM(amount) FROM tblinvoicegroup by ItemID, dbo.CombineValues(ItemID)
--Chandu