USP_ATTRIBUTE_DELETECONSTITUENTVALUE

Deletes the constituent record from all constituent attribute type tables.

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN

Definition

Copy


create procedure dbo.USP_ATTRIBUTE_DELETECONSTITUENTVALUE
(
    @CONSTITUENTID uniqueidentifier
)
as                
    set nocount on;

    declare @TABLENAME nvarchar(128);
    declare @COLUMNNAME nvarchar(128);
    declare @SQL nvarchar(500);

    declare attribute_cursor cursor local fast_forward for 
            select TABLECATALOG.TABLENAME, ATTRIBUTECATEGORY.VALUECOLUMNNAME from dbo.ATTRIBUTECATEGORY inner join dbo.TABLECATALOG on TABLECATALOG.ID = ATTRIBUTECATEGORY.TABLECATALOGID where DATATYPECODE = 6;


    open attribute_cursor;
    fetch next from attribute_cursor into @TABLENAME, @COLUMNNAME;

    while @@fetch_status = 0
    begin

        set @SQL = 'delete from dbo.' + @TABLENAME + ' where ' + @COLUMNNAME + ' = ''' + cast(@CONSTITUENTID as nvarchar(36)) + '''';
        exec sp_executesql @SQL;

        fetch next from attribute_cursor into @TABLENAME, @COLUMNNAME;
    end

    close attribute_cursor;
    deallocate attribute_cursor;