All pastes #200534 Raw Edit

Something

public text v1 · immutable
#200534 ·published 2006-10-13 07:04 UTC
rendered paste body
create procedure sp_insertCategory
(
	@idParent int = null ,
	@name varchar(150) ,
	@is_active bit = null
)
as
set nocount on
begin

	if ( @idParent is null )
	begin
		if ( exists(select id from _category where idParent is null and name = @name) )
		begin
		
			raiserror 50005 'The category '+ @name +' already exists'
			return
			
		end
	end else begin
		if ( exists(select id from _category where idParent = @idParent and name = @name) )
		begin
		
			raiserror 50005 'That category '+ @name +' already exists'
			return
		
		end
	end
	
	if ( @is_active is null )
		set @is_active = 0

	insert into _category ( idParent , name , is_active ) values ( @idParent , @name , @is_active )
	
	return @@identity

end

go