【发布时间】:2021-08-15 03:34:19
【问题描述】:
我不断收到此错误
初始化 sqlcmd 库失败,错误号为 -2147467259
当我尝试执行以下 SQL 代码时。这是一个普通查询,而不是通过 SQL Server 代理。
declare @SQL varchar(8000)
set @SQL = 'select a.b.value(''(../../@ID)'',''varchar(100)'') as [System-ID]
from [DB].[Schema].[Configuration] R
outer apply R.[Configuration].nodes(''root/System/Role/Authorization'') as a(b)
where R.[Report ID] = ''IT.00004'''
print @SQL
exec msdb.dbo.sp_send_dbmail
@profile_name = 'servername',
@recipients = 'info@company.com',
@subject = 'Test B',
@query = @SQL
但是,当我按照以下方式修改查询时,一切正常。
declare @SQL varchar(8000)
set @SQL = 'select *
from [DB].[Schema].[Configuration] R
where R.[Report ID] = ''IT.00004'''
print @SQL
exec msdb.dbo.sp_send_dbmail
@profile_name = 'servername',
@recipients = 'info@company.com',
@subject = 'Test B',
@query = @SQL
所以问题肯定出在语句的这一部分(我在“Configuration”表中引用了一个名为“Configuration”的XML列->列名和表名相同):
outer apply R.[Configuration].nodes('root/System/Role/Authorization') as a(b)
当我在msdb.dbo.sp_send_dbmail 语法之外运行这两个查询时,它们都运行得很好。
有人知道发生了什么吗?我怀疑它与权限相关,因为导致问题的部分使用的是不会导致任何问题的同一张表。
【问题讨论】:
标签: sql-server xml sqlcmd sp-send-dbmail outer-apply