Partilhar via


SET CONCAT_NULL_YIELDS_NULL (Transact-SQL)

Controls whether concatenation results are treated as null or empty string values.

Important

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

Topic link iconTransact-SQL Syntax Conventions

Syntax

SET CONCAT_NULL_YIELDS_NULL { ON | OFF } 

Remarks

When SET CONCAT_NULL_YIELDS_NULL is ON, concatenating a null value with a string yields a NULL result. For example, SELECT 'abc' + NULL yields NULL. When SET CONCAT_NULL_YIELDS_NULL is OFF, concatenating a null value with a string yields the string itself (the null value is treated as an empty string). For example, SELECT 'abc' + NULL yields abc.

If SET CONCAT_NULL_YIELDS is not specified, the setting of the CONCAT_NULL_YIELDS_NULL database option applies.

Note

SET CONCAT_NULL_YIELDS_NULL is the same setting as the CONCAT_NULL_YIELDS_NULL setting of ALTER DATABASE.

The setting of SET CONCAT_NULL_YIELDS_NULL is set at execute or run time and not at parse time.

SET CONCAT_NULL_YIELDS_NULL must be ON when you are creating or changing indexes on computed columns or indexed views. If SET CONCAT_NULL_YIELDS_NULL is OFF, any CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail. For more information about required SET option settings with indexed views and indexes on computed columns, see "Considerations When You Use the SET Statements" in SET (Transact-SQL).

When CONCAT_NULL_YIELDS_NULL is set to OFF, string concatenation across server boundaries cannot occur.

Examples

The following example showing using both SET CONCAT_NULL_YIELDS_NULL settings.

PRINT 'Setting CONCAT_NULL_YIELDS_NULL ON';
GO
-- SET CONCAT_NULL_YIELDS_NULL ON and testing.
SET CONCAT_NULL_YIELDS_NULL ON;
GO
SELECT 'abc' + NULL ;
GO

-- SET CONCAT_NULL_YIELDS_NULL OFF and testing.
SET CONCAT_NULL_YIELDS_NULL OFF;
GO
SELECT 'abc' + NULL; 
GO

See Also

Reference

SET (Transact-SQL)
SESSIONPROPERTY (Transact-SQL)

Other Resources

Setting Database Options

Help and Information

Getting SQL Server 2005 Assistance