user identification

  • Is there a way in tsql to get the system user name (name of person logged in)?

    Is there syntax that will capitalize the first letter of a word (name) and make the rest of the entry lower case?

    Thanks so much.

    Sam

  • Use USER_NAME() or CURRENT_USER function

    See BOL ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/29248949-325b-4063-9f55-5a445fb35c6e.htm

    You can capitialize the first character of any word using something like:

    SELECT UPPER(SUBSTRING(LastName,1,1)) + SUBSTRING(LastName,2,LEN(LastName))

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • One more synonym for USER_NAME() is USER. No parentheses needed for that version which doesn't have the optional parameter.

    For converting names to mixed case, I'll guess you've already discovered that there's a LOWER() function in addition to the UPPER() that BitBucket suggested. Declare @Lastname char(40)

    set @LastName = 'ANDERSON'

    SELECT UPPER(SUBSTRING(@LastName,1,1)) + LOWER(SUBSTRING(@LastName,2,LEN(@LastName)))

    set @LastName = 'MCCOY'

    SELECT UPPER(SUBSTRING(@LastName,1,1)) + LOWER(SUBSTRING(@LastName,2,LEN(@LastName)))

    --Results:

    --Anderson

    --MccoyMy main caveat for using them on persons' names is that since not all names follow the rule of first letter only capitalized, you could end up with some unhappy customers, for instance. Mr. McCoy may not appreciate being addressed as Mr. Mccoy.

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

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