IF NOT EXISTS (SELECT * FROM SYSCOLUMNS INNER JOIN SYSOBJECTS ON SYSOBJECTS.id = SYSCOLUMNS.id 
               WHERE SYSCOLUMNS.NAME = 'AYYIHESAPID' AND SYSOBJECTS.name = 'SUBEBOLUM')
ALTER TABLE dbo.SUBEBOLUM ADD
	AYYIHESAPID int NULL,
	AYYDHESAPID int NULL,
	YTYIHESAPID int NULL,
	YTYDHESAPID int NULL,
	INDHESAPID int NULL
GO

IF NOT EXISTS (SELECT TOP 1 * FROM SUBEBOLUM WHERE AYYIHESAPID IS NOT NULL OR AYYDHESAPID IS NOT NULL OR YTYIHESAPID IS NOT NULL OR YTYDHESAPID IS NOT NULL OR INDHESAPID IS NOT NULL)
	UPDATE    SUBEBOLUM
	SET              AYYIHESAPID = TBOLUM.AYYIHESAPID, AYYDHESAPID = TBOLUM.AYYDHESAPID, YTYIHESAPID = TBOLUM.YTYIHESAPID, YTYDHESAPID = TBOLUM.YTYDHESAPID, 
						  INDHESAPID = TBOLUM.INDHESAPID
	FROM         TBOLUM INNER JOIN
						  SUBEBOLUM ON TBOLUM.BOLUMID = SUBEBOLUM.BOLUMID
	WHERE        (TBOLUM.AYYIHESAPID IS NOT NULL OR TBOLUM.AYYDHESAPID IS NOT NULL OR TBOLUM.YTYIHESAPID IS NOT NULL OR TBOLUM.YTYDHESAPID IS NOT NULL OR TBOLUM.INDHESAPID IS NOT NULL) AND
						  SUBEBOLUM.AYYIHESAPID IS NULL AND SUBEBOLUM.AYYDHESAPID IS NULL AND SUBEBOLUM.YTYIHESAPID IS NULL AND SUBEBOLUM.YTYDHESAPID IS NULL AND SUBEBOLUM.INDHESAPID IS NULL
GO                      