0
I need to check the amount of 0, NULL or empty in fields of different types, My difficulty is when it comes to fields of type XML. I tried to include in my logic the function exist(), but I do not know if it is the best way to do this check, using the code I have done before.
/*vérifie si la colonne numérique a des zéros et si la colonne avec des textes est vide (ou ne contient que espaces)*/
if @dataType IN ('int', 'bit', 'smallint', 'numeric', 'float', 'bigint', 'varbinary')
set @checks = '[' +@colName +']' + '=0'
else if @dataType IN ('varchar', 'char', 'nvarchar', 'date', 'datetime')
set @checks = ' ltrim(rtrim(['+ @colName + '])) ' + 'like '''''
else if @dataType IN ('xml')
/*vérifie si est nullable et si la colonne est nule*/
if @isNullable = 1
if LEN(@checks)> 0
set @checks = @checks + ' OR [' + @colName + '] IS NULL '
else
set @checks = '[' +@colName + '] IS NULL '
set @queryStat = @queryStat + @checks
EXEC sp_executesql @queryStat, @paramDefinition , @cnt = @vides output
I tried to check only if it was null, but I got the error below, as if I hadn’t checked for type xml Xml data type is not supported in Distributed queries. Remote Object 'CTCL-dbpdata24 sql2016.blatuio269_Prd.dbo.tabStagingMessages' has xml column(s)
– Raquel Andrade
Oi Raquel. The error is not pq the xml is null, but rather that the xml type is not supported in distributed queries. I imagine inside
sp_executesql
have something likeSELECT XXX FROM LINK.MinhaBAse.dbo.TabelaX;
. In this case, you would have to cast the xml for another type, but then you would have to see the stored.– mari
That’s right. I’ll have to do it another way. Thank you!
– Raquel Andrade