if exists(select 1 from sysobjects where name = 'ISGrantBranch')
   drop FUNCTION ISGrantBranch
go

CREATE FUNCTION ISGrantBranch( @Branch_NO varchar(6))
RETURNS int
WITH ENCRYPTION
AS
BEGIN
	
	DECLARE @OperID varchar(10)
	RETURN 1
	Select @OperID = OperID From t_sys_spid where spid = @@spid

	IF @OperID = '1001' RETURN 1
	
	IF Exists( select 1 from t_sys_branch_grantt where oper_id = @OperID and Branch_No = Left(@Branch_NO,3) and data_grant = 1 )
	RETURN 1
	
	RETURN 0

END
go