UFN_RESPONSE_RESPONSECATEGORYCODEUNIQUE

Checks to make sure that, if the code on a response is filled in, then it is unique within that category.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN
@RESPONSECATEGORYID uniqueidentifier IN
@CODE nvarchar(10) IN

Definition

Copy


create function dbo.[UFN_RESPONSE_RESPONSECATEGORYCODEUNIQUE]
(
  @ID uniqueidentifier,
  @RESPONSECATEGORYID uniqueidentifier,
  @CODE nvarchar(10)
)
returns bit
as
  begin
    declare @UNIQUE bit;
    declare @COUNT integer;

    set @UNIQUE = 1;

    if len(isnull(@CODE, '')) > 0
      if exists(select top 1 1 from dbo.[RESPONSE] where [RESPONSECATEGORYID] = @RESPONSECATEGORYID and [CODE] = @CODE and [ID] <> @ID)
        set @UNIQUE = 0;

    return @UNIQUE;
  end