  
CREATE OR ALTER VIEW VStk_RenkBedenGirisCikisDepo   
AS  
SELECT StokKodu,  
  Beden,  
  Renk,  
        (SELECT ISNULL(SUM(Miktar), 0) AS Expr1 FROM dbo.RenkBedenHareket   
        WHERE (StokKodu = AnaTablo.StokKodu) AND   
     (GC = 'G') AND   
     (Beden = AnaTablo.Beden) and   
     (Renk = AnaTablo.Renk) AND   
     (Depo = AnaTablo.Depo) and  
     (HT = AnaTablo.HT)) AS Giris,  
  (SELECT ISNULL(SUM(Miktar), 0) AS Expr1 FROM dbo.RenkBedenHareket  
   WHERE (StokKodu = AnaTablo.StokKodu) AND   
      (GC = 'C') AND   
      (Beden = AnaTablo.Beden) and   
     (Renk = AnaTablo.Renk) AND   
     (Depo = AnaTablo.Depo) and  
     (HT = AnaTablo.HT)) AS Cikis,  
  (SELECT ISNULL(SUM(Miktar), 0) AS Expr1 FROM dbo.RenkBedenHareket   
        WHERE (StokKodu = AnaTablo.StokKodu) AND   
     (GC = 'G') AND   
     (Beden = AnaTablo.Beden) and   
     (Renk = AnaTablo.Renk) AND   
     (Depo = AnaTablo.Depo)and  
     (HT = AnaTablo.HT))-  
  (SELECT ISNULL(SUM(Miktar), 0) AS Expr1 FROM dbo.RenkBedenHareket  
   WHERE (StokKodu = AnaTablo.StokKodu) AND   
      (GC = 'C') AND   
      (Beden = AnaTablo.Beden) and   
     (Renk = AnaTablo.Renk) AND   
     (Depo = AnaTablo.Depo) and  
     (HT = AnaTablo.HT)) AS Fark,  
     Depo, HT,
	 (select rb.Barkodu from RenkBedenTablosu rb where rb.StokKodu = AnaTablo.StokKodu and rb.Beden = AnaTablo.Beden and rb.Renk = AnaTablo.Renk) Barkodu
FROM         dbo.RenkBedenHareket AS AnaTablo  
group by StokKodu,Beden,Renk,Depo,HT