SET CONCAT_NULL_YIELDS_NULL (Transact-SQL)SET CONCAT_NULL_YIELDS_NULL (Transact-SQL)
Se aplica a:Applies to: SQL ServerSQL Server (todas las versiones admitidas)
SQL ServerSQL Server (all supported versions)
Instancia administrada de Azure SQLAzure SQL Managed Instance
Instancia administrada de Azure SQLAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Almacenamiento de datos paralelosParallel Data Warehouse
Almacenamiento de datos paralelosParallel Data Warehouse
SQL ServerSQL Server (todas las versiones admitidas)
SQL ServerSQL Server (all supported versions)
Instancia administrada de Azure SQLAzure SQL Managed Instance
Instancia administrada de Azure SQLAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Almacenamiento de datos paralelosParallel Data Warehouse
Almacenamiento de datos paralelosParallel Data Warehouse
Determina si los resultados de la concatenación se tratan como valores NULL o como valores de cadena vacía.Controls whether concatenation results are treated as null or empty string values.
Importante
En una versión futura de SQL ServerSQL Server, CONCAT_NULL_YIELDS_NULL siempre estará establecida en ON y cualquier aplicación que establezca de forma explícita la opción en OFF generará un error.In a future version of SQL ServerSQL Server CONCAT_NULL_YIELDS_NULL will always be ON and any applications that explicitly set the option to OFF will generate an error. Evite utilizar esta característica en nuevos trabajos de desarrollo y tenga previsto modificar las aplicaciones que actualmente la utilizan.Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
Convenciones de sintaxis de Transact-SQL
Transact-SQL Syntax Conventions
SintaxisSyntax
-- Syntax for SQL Server
SET CONCAT_NULL_YIELDS_NULL { ON | OFF }
-- Syntax for Azure Synapse Analytics and Parallel Data Warehouse
SET CONCAT_NULL_YIELDS_NULL ON
Nota
Para ver la sintaxis de Transact-SQL para SQL Server 2014 y versiones anteriores, consulte Versiones anteriores de la documentación.To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
ComentariosRemarks
Cuando SET CONCAT_NULL_YIELDS_NULL es ON, al concatenar un valor NULL con una cadena se produce como resultado NULL.When SET CONCAT_NULL_YIELDS_NULL is ON, concatenating a null value with a string yields a NULL result. Por ejemplo, SELECT 'abc' + NULL
produce NULL
.For example, SELECT 'abc' + NULL
yields NULL
. Cuando SET CONCAT_NULL_YIELDS_NULL es OFF, al concatenar un valor NULL con una cadena se obtiene la propia cadena (el valor NULL se trata como una cadena vacía).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). Por ejemplo, SELECT 'abc' + NULL
produce abc
.For example, SELECT 'abc' + NULL
yields abc
.
Si no se especifica SET CONCAT_NULL_YIELDS_NULL, se aplica la configuración de la opción de base de datos CONCAT_NULL_YIELDS_NULL.If SET CONCAT_NULL_YIELDS_NULL is not specified, the setting of the CONCAT_NULL_YIELDS_NULL database option applies.
Nota
La opción SET CONCAT_NULL_YIELDS_NULL es igual que la opción CONCAT_NULL_YIELDS_NULL de ALTER DATABASE.SET CONCAT_NULL_YIELDS_NULL is the same setting as the CONCAT_NULL_YIELDS_NULL setting of ALTER DATABASE.
La opción SET CONCAT_NULL_YIELDS_NULL se establece en tiempo de ejecución, no en tiempo de análisis.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 debe ser ON al crear o cambiar vistas indexadas, índices en columnas calculadas, índices filtrados o índices espaciales.SET CONCAT_NULL_YIELDS_NULL must be ON when creating or altering indexed views, indexes on computed columns, filtered indexes or spatial indexes. Si SET CONCAT_NULL_YIELDS_NULL es OFF, las instrucciones CREATE, UPDATE, INSERT y DELETE en tablas con índices, en columnas calculadas, en índices filtrados, en índices espaciales o en vistas indexadas generarán errores.If SET CONCAT_NULL_YIELDS_NULL is OFF, any CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns, filtered indexes, spatial indexes or indexed views will fail. Para más información sobre las configuraciones de las opciones SET necesarias con vistas indizadas e índices en columnas calculadas, vea el apartado "Consideraciones al utilizar las instrucciones SET" en Instrucciones SET (Transact-SQL).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 Statements (Transact-SQL).
Cuando CONCAT_NULL_YIELDS_NULL se establece en OFF, no se puede producir la concatenación de cadenas entre los límites del servidor.When CONCAT_NULL_YIELDS_NULL is set to OFF, string concatenation across server boundaries cannot occur.
Para ver la configuración actual de este valor, ejecute la consulta siguiente.To view the current setting for this setting, run the following query.
DECLARE @CONCAT_SETTING VARCHAR(3) = 'OFF';
IF ( (4096 & @@OPTIONS) = 4096 ) SET @CONCAT_SETTING = 'ON';
SELECT @CONCAT_SETTING AS CONCAT_NULL_YIELDS_NULL;
EjemplosExamples
En el ejemplo siguiente se muestra el uso de los dos valores de SET CONCAT_NULL_YIELDS_NULL
.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
Consulte tambiénSee Also
Instrucciones SET (Transact-SQL) SET Statements (Transact-SQL)
SESSIONPROPERTY (Transact-SQL)SESSIONPROPERTY (Transact-SQL)