---- UnomIdByValue ----
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UnomIdByValue]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[UnomIdByValue]
GO
create function UnomIdByValue(@Value float)
returns Integer
as
begin
  declare @Res int
  if @Value>900 set @Res=1 else
  if @Value>700 set @Res=2 else
  if @Value>=400 set @Res=3 else
  if @Value>300 set @Res=4 else
  if @Value>200 set @Res=5 else
  if @Value>80 set @Res=6 else
  if @Value>22 set @Res=7 else
  if @Value>8 set @Res=8 else
  if @Value>1 set @Res=9 else
  set @Res=10
  return @Res
end
