How to Pre-Pend Value to Existing Value While Creating a Temp Column?

  • I am looking for a way to create a temp column who's value would take the value of another column and pre-pend a value like this to it "domain\". This is the Select statement I currently have:

    SELECT Nalphakey,[Last Name],[First Name],[User Name],[E-mail Address],[User Name]

    FROM SkywardUserProfiles

    I understand how to create an Alias for an existing column, but not sure how to do what I am wanting. I also understand that the following will do the concatenation that I need, but I have only used it in an UPDATE query, and I'm not sure how to use it within a Select statement or if that's even possible:

    domainName=CONCAT('domain\',User Name);

    I am sorry for the lack of understanding of SQL, but any help would be greatly appreciated.

  • You can use literal values and variables much the same way you reference columns in a SELECT statement, and you may mix them.

    This shows adding a literal Domain value to the [User Name] column, plus some extra columns to show literal-value tricks.

    SELECT 'This is just a string' AS [Just A String Literal],

    'This is two str' + 'ings added together' AS [TwoStringsAddedTogether],

    100 + 22.5 + (300/2) AS [And Some Numbers],

    'domain\' + [User Name] AS [Domain Name],

    Nalphakey,[Last Name],[First Name],

    [First Name] + ' ' + [Last Name] AS [Full Name],

    [User Name],[E-mail Address], [User Name]

    FROM SkywardUserProfiles

    Eddie Wuerch
    MCM: SQL

  • Select (FirstName + '/domain') as myfield

    So FirstName is the name of one of your fields (used as an example) and the part after is what you want to add

    <hr noshade size=1 width=250 color=#BBC8E5> Regards,Jeffery Williams http://www.linkedin.com/in/jwilliamsoh

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply