USE [Ent_TOKLU]

 IF   EXISTS (SELECT *  FROM sys.tables WHERE  name='STOKKARTI')
 BEGIN 
 ALTER TABLE  Ent_TOKLU.dbo.STOKKARTI NOCHECK CONSTRAINT ALL
 drop table Ent_TOKLU.dbo.STOKKARTI 
end

 IF   EXISTS (SELECT *  FROM sys.tables WHERE  name='StokFiyat')
 BEGIN 
 ALTER TABLE  Ent_TOKLU.dbo.StokFiyat NOCHECK CONSTRAINT ALL
 drop table Ent_TOKLU.dbo.StokFiyat 
end 

 IF   EXISTS (SELECT *  FROM sys.tables WHERE  name='StokBarkodlari')
 BEGIN 
 ALTER TABLE  Ent_TOKLU.dbo.StokBarkodlari NOCHECK CONSTRAINT ALL
 drop table Ent_TOKLU.dbo.StokBarkodlari 
end 
 
SELECT   * INTO Ent_TOKLU.dbo.[STOKKARTI] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[STOKKARTI] 
GO
SELECT   * INTO Ent_TOKLU.dbo.[StokFiyat] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[StokFiyat]
GO
SELECT   * INTO Ent_TOKLU.dbo.[StokBarkodlari] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[StokBarkodlari] 

UPDATE STOKKARTI SET StokAdedi = (SELECT ISNULL(SUM(Miktar*(CASE GC WHEN 'G' THEN 1 WHEN 'C' THEN -1 END)), 0) FROM STOKHAR 
	WHERE StokKodu = STOKKARTI.Kodu and STOKHAR.FisTuru<>'İ') WHERE StokTipi in ('+ Ürün','+ Ambalaj') 


 