Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Get User Details Function

Posted on August 6, 2013October 26, 2015 By David Kittell
-- 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
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.

Related

Code MSSQL

Post navigation

Previous post
Next post

Related Posts

Ektron Find Replace In UrlAliasManual

Posted on October 23, 2013October 26, 2015

This script will rename manual aliases set xact_abort on declare @currval nvarchar(500) declare @newval nvarchar(500) declare @search nvarchar(500) declare @replace varchar(500) set @search = ‘/Index’ –string to find set @replace = ‘/Default’ –replacement string declare @pos int declare @id bigint begin tran declare curs cursor local fast_forward for select AliasId,AliasName…

Read More

MS SQL – Count Users In User Role

Posted on October 10, 2016

SELECT UR.[Id] ,UR.[Name] ,COUNT(ur.name) FROM [dbo].[UserRole] UR INNER JOIN dbo.[User] U ON U.Role = UR.Id GROUP BY UR.Id, ur.Name 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…

Read More

Excel – VLookup – Unique Join WorkSheets

Posted on February 10, 2016February 12, 2016

=VLOOKUP(B2,Sheet2!A:B,2,FALSE) Sheet1 Column A Column B Moo ./.htaccess Sheet2 Column A Column B ./.htaccess 235 Add the code above to Column C in Sheet1 and it will match Column B from Sheet1 with Column A from Sheet2 and get the value to display from Column B from Sheet2 Originally Posted…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes