using Functions
/*This fuction we use it almost with lookup table to return the name it takes two parameters first one display the table and the second one display the id that we want to return its related name*/
USE
[databaseName]
GO
SET
/****** Object: UserDefinedFunction [dbo].[GetName] **/
ANSI_NULLS
ONGO
SET
QUOTED_IDENTIFIER
ALTER function [dbo].[GetName](@Flag int, @ID int)
Returns
varchar(120)Begin
DECLARE
@Name varchar(120
– 1:Site 2:JobLevel 3:Role
IF
END
ELSE IF @Flag=2 BEGIN select @Name=JobLevelDesc from dbo.JobLevel where JobLevelID=@ID
END
ELSE IF @Flag=3 BEGIN select @Name=RoleDesc from dbo.UserRoles where RoleID =@ID
@Flag=1 BEGIN select @Name=SiteDesc from dbo.Site where SiteID=@ID
)ONGO
END
Return
@Name
END
Advertisement