SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ntm_get_children]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[ntm_get_children] GO create Procedure ntm_get_children @ErrorMessage varchar(250) = Null Output -- * Error message returned to caller object ,@TreeID varchar(36) = null ,@InternalNodeID varchar(36) = null as begin declare @ntm_left integer declare @ntm_right integer IF (@TreeID Is Null) BEGIN SET @ErrorMessage = 'The TreeID parameter can not be null.' GOTO on_error END IF (@InternalNodeID Is Null) BEGIN SET @ErrorMessage = 'The InternalNodeID parameter can not be null.' GOTO on_error END select @ntm_left = nleft ,@ntm_right = nright from ntm_nodes where TreeID = @TreeID and nt.InternalNodeID = @InternalNodeID select InternalNodeID from ntm_nodes where TreeID = @TreeID and nleft <> @ntm_left and nleft between @ntm_left and @ntm_right theEnd: return(1) on_error: return(-1) end GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO