IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'SAKLAMABIRIMMIKTAR' AND SYSOBJECTS.name = 'STOK')
ALTER TABLE dbo.STOK ADD
	SAKLAMABIRIMMIKTAR numeric(9,2) NULL
GO


IF EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'SAKLAMABIRIMMIKTAR' AND SYSOBJECTS.name = 'TITEM')
BEGIN
	DECLARE 
	  @CMD nvarchar(300)
	
	SET @CMD = 
		N'UPDATE STOK SET SAKLAMABIRIMMIKTAR = TITEM.SAKLAMABIRIMMIKTAR  FROM STOK INNER JOIN 
		  TITEM ON TITEM.STOKID = STOK.STOKID WHERE TITEM.SAKLAMABIRIMMIKTAR IS NOT NULL AND STOK.SAKLAMABIRIMMIKTAR IS NULL'
	EXEC (@CMD)
	
	ALTER TABLE dbo.TITEM 
		DROP CONSTRAINT DF_TITEM_SAKLAMABIRIMMIKTAR
	ALTER TABLE dbo.TITEM
		DROP COLUMN SAKLAMABIRIMMIKTAR

END
GO