Query Substring and Uppercase

  • SUBSTRING(PAYROLL_EMP.WEBADDR, - 1, CHARINDEX('@', PAYROLL_EMP.WEBADDR) + 1) AS USERNAME,

    Example:

    Column PAYROLL_EMP.WEBADDR contains value jdoe@servercentral.com

    The above statement returns jdoe as USERNAME

    Is there a way to have JDOE returned in UPPERCASE

  • Typically I would suggest doing formatting at the presentation layer, not the database layer, but if you need to do it in the query, then you can just make the SUBSTRING the input to the UPPER function (https://msdn.microsoft.com/en-us/library/ms180055.aspx.

    Cheers!

  • Use the UPPER function.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • SUBSTRING(UPPER(PAYROLL_EMP.WEBADDR, - 1, CHARINDEX('@', PAYROLL_EMP.WEBADDR) + 1) AS USERNAME,

    SQL returns this error...

    Msg 174, Level 15, State 1, Line 30

    The upper function requires 1 argument(s).

  • You don't have the correct scope for the UPPER.

    At any rate, it's simpler to do it the other way around, since you already have the SUBSTRING working. Just take the SUBSTRING and pass it to UPPER, instead of doing an UPPER and then taking a SUBSTRING.

    UPPER(SUBSTRING(PAYROLL_EMP.WEBADDR, - 1, CHARINDEX('@', PAYROLL_EMP.WEBADDR) + 1))

    Cheers!

  • Thank you Jacob! Appreciate your help! Kind regards, Bob

Viewing 6 posts - 1 through 6 (of 6 total)

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