CREATE OR ALTER PROCEDURE [dbo].[sp_Link_StokKart_Sil]
AS
BEGIN
select  *from a
    IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'STOKKARTI')
    BEGIN
        ALTER TABLE STOKKARTI NOCHECK CONSTRAINT ALL;
        DROP TABLE STOKKARTI;
    END
END
go


CREATE or alter PROCEDURE [dbo].[sp_Link_StokKart_Sil] 
as
BEGIN
	IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'STOKKARTI')
	 BEGIN 
	 ALTER TABLE  STOKKARTI NOCHECK CONSTRAINT ALL;
	 DROP table STOKKARTI ;
	end

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


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


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

end

 go
-------------------------------------------------------------------------------------------------------------------------------------------
 CREATE or alter PROCEDURE [dbo].[sp_Link_StokKart_Al] 
 as
SELECT   * INTO [STOKKARTI] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[STOKKARTI] 
go

 CREATE or alter PROCEDURE [dbo].[sp_Link_StokFiyat_Barkod_Al]   
 as
SELECT   * INTO [StokFiyat] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[StokFiyat]
SELECT   * INTO [StokBarkodlari] FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[StokBarkodlari] 
go

 CREATE or alter PROCEDURE [dbo].[sp_Link_StokFiyatDegisim_Al]   
as
SELECT  top 1000 * INTO StokFiyatDegisim FROM [81.214.220.4,14500].[Ent_MARKA23].dbo.[StokFiyatDegisim] order by ID DESC

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') 


 go

  
SELECT   count(*) FROM [STOKKARTI] 
GO
SELECT   count(*) FROM [StokFiyat] 
GO
SELECT   count(*) FROM [StokBarkodlari] 
GO
SELECT    count(*) FROM StokFiyatDegisim   

create or alter proc [sp_Link_StokKart_Aktar]    
as 
exec sp_Link_StokKart_Sil
exec sp_Link_StokFiyat_Barkod_Al
exec sp_Link_StokFiyatDegisim_Al
exec sp_Link_StokKart_Al

