---- GetSupportType ----
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetSupportType]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[GetSupportType]
GO
create function GetSupportType(@D nvarchar(50), @IsAnchor bit, @IsTransposition bit)
returns Integer
as
begin
  declare @res as Integer
  set @res = 0
  if @D LIKE '%промежут%'
    if @D LIKE '%угловая%' set @res = 2
    else set @res = 1
  else
    if IsNull(@IsAnchor, 0)=1
      if @D LIKE '%угловая%' set @res = 4
      else set @res = 3
    else
      if IsNull(@IsTransposition, 0)=1 set @res = 5
      else
        if @D LIKE '%специальная%' set @res = 6
  return @res
end
