USE ManageSoft
GO

IF EXISTS(SELECT * FROM sysobjects WHERE xtype = 'P'
		AND [name] = 'CheckHardwareClass'
)
		DROP PROCEDURE CheckHardwareClass
GO
CREATE PROCEDURE CheckHardwareClass
	@Class NVARCHAR(256),
	@SuperClass NVARCHAR(256) = NULL
AS
	IF NOT EXISTS (
		SELECT *
		FROM HardwareClass
		WHERE Class = @Class
	)
		INSERT INTO HardwareClass (Class, SuperClassID)
			VALUES (@Class, NULL)

	DECLARE @SuperClassID INT

	SELECT	@SuperClassID = HardwareClassID
	FROM	HardwareClass
	WHERE	Class = @SuperClass

	UPDATE	HardwareClass
	SET	SuperClassID = @SuperClassID
	WHERE	Class = @Class

GO

EXEC CheckHardwareClass 'MGS_BIOS', 'CIM_BIOSElement'
EXEC CheckHardwareClass 'MGS_VideoController', 'CIM_PCVideoController'
EXEC CheckHardwareClass 'MGS_ComputerSystemProduct', 'CIM_Product'

DROP PROCEDURE CheckHardwareClass
GO
