-- Get User's First Name, Last Name SELECT dbo.GetUserDetails(120, 1) -- Get User's Last Name, First Name SELECT dbo.GetUserDetails(120, 4) -- Get User's Username SELECT dbo.GetUserDetails(120, 2) -- Get User's Email Address SELECT dbo.GetUserDetails(120, 3)
IF OBJECT_ID(N'dbo.GetUserDetails') IS NOT NULL DROP FUNCTION dbo.GetUserDetails GO CREATE FUNCTION dbo.GetUserDetails ( @userid INT ,@option INT ) RETURNS VARCHAR(250) AS BEGIN DECLARE @UserDetails VARCHAR(250) SET @UserDetails = ( CASE WHEN @option = 1 -- Get User's First Name and Last Name THEN ( SELECT dbo.properCase((firstName + ' ' + lastName)) AS NAME FROM tblUsers WHERE id = @userid ) WHEN @option = 2 -- Get User's Username THEN ( SELECT userID FROM tblUsers WHERE id = @userid ) WHEN @option = 3 -- Get User's Email Address THEN ( SELECT eMail FROM tblUsers WHERE id = @userid ) WHEN @option = 4 -- Get User's Last Name and First Name THEN ( SELECT dbo.properCase((lastName + ' ' + firstName)) AS NAME FROM tblUsers WHERE id = @userid ) END ) RETURN @UserDetails END GO
Last Updated on October 26, 2015