Last active
June 20, 2016 22:10
-
-
Save sarangbk/007a2d9cbf7eddbb234201ff66657500 to your computer and use it in GitHub Desktop.
-- Convert Down Level Logon format e.g. domain\username to User Principal Name (UPN) format [email protected]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Convert Down Level Logon format e.g. domain\username to User Prindipal Name (UPN) format [email protected] | |
-- The formats are explained here https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx | |
IF OBJECT_ID (N'[dbo].[uFnGetDomainAtFromDomainSlash]', N'FN') IS NOT NULL | |
DROP FUNCTION uFnGetDomainAtFromDomainSlash; | |
GO | |
CREATE FUNCTION [dbo].[uFnGetDomainAtFromDomainSlash](@AccountNameWithDomainSlash VARCHAR(MAX), @DomainExtension VARCHAR(MAX)) | |
RETURNS VARCHAR(MAX) | |
AS | |
BEGIN | |
DECLARE @AccountName VARCHAR(MAX), | |
@DomainName VARCHAR(MAX) | |
SET @AccountName = SUBSTRING ( @AccountNameWithDomainSlash, PATINDEX('%\%',@AccountNameWithDomainSlash) + 1, 100) | |
SET @DomainName = SUBSTRING ( @AccountNameWithDomainSlash, 0, PATINDEX('%\%',@AccountNameWithDomainSlash)) | |
RETURN CONCAT(@AccountName, '@', @DomainName, @DomainExtension) | |
END; | |
GO | |
-- Usage | |
-- This will convert 'wayne-industries\bruce.wayne' to '[email protected]' | |
SELECT [dbo].[uFnGetDomainAtFromDomainSlash]('wayne-industries\bruce.wayne', '.gotham')AS AccountNamwWithDomain |
@ynotcme01000 thanks, good point, done.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should add a preview of what you want to create that way i will be useful tdo that we can understand..