
IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.[GetOwnDepLink]') AND xtype in (N'FN', N'IF', N'TF'))
DROP FUNCTION dbo.[GetOwnDepLink]

GO

/*
c Кейсистемс (Keysystems), 2005
*/
CREATE   FUNCTION [GetOwnDepLink]()
RETURNS int
AS
BEGIN
RETURN (SELECT TOP 1 LINK FROM dbo.DEPARTMENTS WHERE TYPE = 4)
END

GO

GRANT EXECUTE ON dbo.[GetOwnDepLink] TO PUBLIC

GO

DECLARE @dbname NVARCHAR(254)
SET @dbname = db_name()
EXEC dbo.sp_dbcmptlevel @dbname=@dbname, @new_cmptlevel=90
GO

--Таблица OKPD
IF not exists(select * from sysobjects where id = object_id('[dbo].[OKPD]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE [dbo].[OKPD] (
	[LINK] int NOT NULL IDENTITY(1,1) ,
	[LINK_SELF] int NULL ,
	[CODE] char(12) NOT NULL ,
	[NAME] varchar(254) NOT NULL ,
	[UM] int NULL ,
	[USED] bit NOT NULL )
GO

