我们最近在 Windows Server 2012(从 Windows Server 2008 R2)上升级到 SQL Server 2012(从 SQL Server 2008 R2),并且之前运行没有错误的 SQL Server 作业代理作业现在失败了。
该作业有一个 Powershell 作业步骤:
$ErrorActionPreference = 'Stop'
$DateStamp = Get-Date -format "yyyyMMdd"
$BizUnit = 'SHB'
# Target File directory
$BaseDir = '\\MyFileServer\MyDirectory'
$Query = "EXEC dbo.usp_MyQuery '$BizUnit'"
$TargetFile = "MyTargetFile_" + $BizUnit + "_$DateStamp.xml"
$TargetDir = (Join-Path -Path $BaseDir -ChildPath $BizUnit)
$Query | Out-File -FilePath (Join-Path -Path $TargetDir -ChildPath $TargetFile) -Force -Encoding "utf8"
Run Code Online (Sandbox Code Playgroud)
当作业运行时,它失败并显示以下错误消息:
作业步骤在 PowerShell 脚本的第 14 行收到错误。对应的行是 '$Query | Out-File -FilePath …
我想从在 SQL Server 2016 中存储为 nvarchar 值的任何任意的、格式良好的 JSON 文档中提取节点名称及其路径的完整列表。有没有可靠的方法来做到这一点?
例如,对于 json 值:
DECLARE @json_doc nvarchar(4000) = '{"Name1":"Value1", "Name2":"Value2"}'
Run Code Online (Sandbox Code Playgroud)
查询@json_doc 时得到这个结果:
NODE_NAME
$.Name1
$.Name2
Run Code Online (Sandbox Code Playgroud)