CREATE VIEW [dbo].[LessKala]
AS
SELECT dbo.TmpDrugHavaleh.K_Code,
       SUM(dbo.TmpDrugHavaleh.K_Qty1) AS Tedad,
       dbo.TmpDrugHavaleh.Sender
FROM dbo.Anbar
    INNER JOIN dbo.TmpDrugHavaleh
        ON dbo.Anbar.A_Code = dbo.TmpDrugHavaleh.Sender
           AND dbo.Anbar.K_Code = dbo.TmpDrugHavaleh.K_Code
    INNER JOIN dbo.KalaId
        ON dbo.Anbar.K_Code = dbo.KalaId.K_Code
    INNER JOIN dbo.TmpDrugH
        ON dbo.TmpDrugHavaleh.Id_Havaleh = dbo.TmpDrugH.Id_Havaleh
GROUP BY dbo.TmpDrugHavaleh.Sender,
         dbo.TmpDrugHavaleh.K_Code,
         dbo.TmpDrugHavaleh.CtrMojodi,
         dbo.KalaId.Name1,
         dbo.TmpDrugH.kind_Save
HAVING (dbo.TmpDrugH.kind_Save = '2')
       AND (LEN(dbo.TmpDrugHavaleh.Sender) = 3);