Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

APP_NAME (Transact-SQL)

Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Returns the application name for the current session if set by the application.

Security note Security Note

The application name is provided by the client and is not verified in any way. Do not use APP_NAME as part of a security check.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.

Topic link icon Transact-SQL Syntax Conventions



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 ;app='application_name'

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;
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) + '.';
PRINT 'This process was started by ' + APP_NAME() + '. The date is ' + CONVERT ( varchar(100) , GETDATE(), 102) + '.';

Community Additions

© 2015 Microsoft