-- 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
Originally Posted on August 6, 2013
Last Updated on October 26, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.