Question

I'm working with SQL Server 2012 express and I want to check if the result of a Select is null.

This is my sql statement:

Set @xml = (Select DATOS from LOTES_ANTERIORES WHERE NOMBRE_LOTE = @nombreLote AND PRODUCTO = @producto)

SET @xmlString = cast(@xml as nvarchar(max))

How can I check if @xml is null?

I'm not sure if @xmlString will return null or not if @xml is null.

Was it helpful?

Solution

IF @xml IS NULL PRINT 'It's null!'

Or to perform more actions, like this:

IF @xml IS NULL
BEGIN
    SELECT 'XML is NULL'
    PRINT 'XML is NULL'
END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top