September 20, 2019 at 12:00 am
Comments posted to this topic are about the item Printing the String
September 20, 2019 at 5:35 am
Nice question, thanks Steve
____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
September 20, 2019 at 8:03 am
Does it make sense to put USER_NAME() in the script? I think no and that is why 31% picked the second answer. 🙂
5ilverFox
Consulting DBA / Developer
South Africa
September 20, 2019 at 1:58 pm
Good question but imho the best answer was not on the list of choices. It would be better to use ORIGINAL_LOGIN() instead of USER_NAME().
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 20, 2019 at 2:40 pm
Agreed,
Wouldn't user USER_NAME() for this purpose
Thanks for the question though
---------------------------------------------------------------------------------------
The more you know, the more you know that you dont know
September 20, 2019 at 4:55 pm
Good question but imho the best answer was not on the list of choices. It would be better to use ORIGINAL_LOGIN() instead of USER_NAME().
It seems to me that the user name is going to be more frequently a useful piece of information.
That said:
IF ORIGINAL_LOGIN()=USER_NAME()
PRINT 'This action was initiated by ' + USER_NAME() + ' and it failed.'
else
PRINT 'This action was initiated by ' ORIGINAL_LOGIN() + ' as ' + USER_NAME() + ' and it failed.'
September 20, 2019 at 5:10 pm
Hmmm, that would still not make sense. Why would you want your own name displayed during debugging? Don't know your own name? 🙂
5ilverFox
Consulting DBA / Developer
South Africa
September 20, 2019 at 6:01 pm
It's useful when doing some things using EXECUTE AS, reverting etc and you want to check which user context is in place at what point in the process.
Sue
September 23, 2019 at 2:53 pm
The best answer is the one that the question asked, which isn't an architectural question on the function usage, but rather, how to PRINT strings.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply