【发布时间】:2014-09-17 08:58:12
【问题描述】:
我最近,大约 2 个月前,需要检查表中具有 NULL 值的任何字段。
我现在正在执行另一项任务,但这次我需要检查表中的任何字段是否具有空字符串值。
开始查询:
;With xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' as ns)
SELECT *
FROM [Schema].[Table] act
where (
select act.*
for xml path('row'), elements xsinil, type
).exist('//*/@ns:nil') = 1
我知道我需要更改@ns:nil,但由于我没有接受过 TSql 的 XQuery 实现方面的教育,因此我需要有人帮助我完成这个初始查询。同样,我应该去 MSDN 之外的地方阅读有关用法和功能的信息。
更新 #1:
;With xmlnamespaces('http://www.w3.org/2001/XMLSchema-instance' as ns)
Select *
from Schema.Table act
where (
select act.*
for xml path('row'), elements xsinil, type
).value('(//row/*)[1]', 'varchar(max)') = ''
试过了,但显然其中一个字段包含字符 0x001C,因此需要转换为二进制、varbinary 或图像,然后使用 BINARY BASE64 指令。
【问题讨论】:
标签: tsql sql-server-2012 xquery