August 7, 2009 at 5:53 am
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
August 7, 2009 at 7:02 am
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))
August 7, 2009 at 1:40 pm
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