Returns the application name for the current session if set by the application.
APP_NAME ( )
Use APP_NAME when you want to perform different actions for different applications. For example, formatting a date differently for different applications, or returning an informational message to certain applications.
To set an application name in Management Studio, in the Connect to Database Engine dialog box, click Options. On the Additional Connection Parameters tab, provide an app attribute in the format
The following example checks whether the client application that initiated this process is a
SQL Server Management Studio session and provides a date in either US or ANSI format.
USE AdventureWorks2012; GO IF APP_NAME() = 'Microsoft SQL Server Management Studio - Query' PRINT 'This process was started by ' + APP_NAME() + '. The date is ' + CONVERT ( varchar(100) , GETDATE(), 101) + '.'; ELSE PRINT 'This process was started by ' + APP_NAME() + '. The date is ' + CONVERT ( varchar(100) , GETDATE(), 102) + '.'; GO