我为SSRS报告编写的sql查询在SSMS中完美执行,但在SSRS报告中运行时无法返回结果。报表服务器或数据库服务器上没有错误。 SSRS报告呈现但不包含任何数据。
我尝试运行SQL分析器,查询根本没有显示。我在服务器上有其他几个正确运行的报告,查询出现在SQL事件探查器中。
破碎的报告中唯一不同的是我使用;WITH XMLNAMESPACES(DEFAULT 'urn:hl7-org:v3')
我得到的结果与SQL Server 2005和2008相同
以下是查询,以及在SSRS中运行时没有返回任何内容的任何想法。我已修改查询以删除/修改可能导致语法错误的客户端信息,但未修改的查询运行并在SSMS中运行时返回结果
Declare @MinDate datetime;
Declare @MaxDate datetime;
DECLARE @fooData TABLE (msgId varchar(100), TransactionName varchar(30),SourceSystem varchar(12),MsgDay date)
;WITH XMLNAMESPACES(DEFAULT 'urn:hl7-org:v3')
INSERT INTO @fooData
SELECT
MsgLogID as msgId
,TransactionName =
CASE LEFT(MsgBody,28)
--WHEN '<qqqResult' THEN 'qqqResult'
WHEN '<qqqResult xmlns=' THEN 'qqqResult'
ELSE 'qqqqRevised'
END
, SourceSystem =
CASE LEFT(MsgBody,21)
--WHEN '<qqqResult' THEN CONVERT(XML,[MsgBody]).value('(/qqqResult/receiver/device/id/@extension)[1]','varchar(1000)')
WHEN '<qqqResult' THEN CONVERT(XML,[MsgBody]).value('(/qqqResult/sender/device/id/@extension)[1]','varchar(1000)')
ELSE CONVERT(XML,[MsgBody]).value('(/qqqRevised/sender/device/id/@extension)[1]','varchar(1000)')
END
, Convert(date,[MsgDateTime]) as MsgDay
FROM [foo].[dbo].[fooMegerPerson_WCF]
WHERE [TransactionStatus] = 'Valid'
SELECT @MaxDate=DATEADD(DAY,0,datediff(day,0, MAX([MsgDateTime]))) ,@MinDate=DATEADD(DAY,0,datediff(day,0, MIN ([MsgDateTime])) )FROM [foo].[dbo].[fooMegerPerson_WCF]
-- Declare a temp table for the query msg type so that we can create a join
DECLARE @msgNameTable TABLE (msgName varchar(30))
INSERT INTO @msgNameTable (msgName)
Values ('qqqResult'),('fooRevised')
DECLARE @sourceTable TABLE (sourceName varchar(10))
INSERT INTO @sourceTable (sourceName)
Values ('foo_1'),('foo_2')
--Select * from @msgNameTable
-- create a date table containing every day between start and end
DECLARE @datetable TABLE (d date)
INSERT INTO @datetable
SELECT TOP (DATEDIFF(DAY, @MinDate, @MaxDate) + 1) Date = DATEADD(DAY, ROW_NUMBER() OVER (ORDER BY a.object_id) - 1,
@MinDate)
FROM sys.all_objects a CROSS JOIN
sys.all_objects b
-- cross join to create a daily entry for every msg type and every source system
DECLARE @dateNameSourceTable TABLE (d date, msgName varchar (30),sourceName varchar(10))
INSERT INTO @dateNameSourceTable
Select dt.d, mn.msgName, st.sourceName from @datetable dt CROSS JOIN @msgNameTable mn CROSS JOIN @sourceTable st
--SELECT * FROM @dateNameSourceTable
Select Count(x.msgId) AS MessageCount,dsn.msgName AS TransactionName ,dsn.d, dsn.sourceName
FROM @fooData as X
RIGHT JOIN @dateNameSourceTable dsn ON x.MsgDay = dsn.d AND x.SourceSystem = dsn.sourceName AND x.TransactionName = dsn.msgName
Group By dsn.d, dsn.msgName, dsn.sourceName
Order By dsn.d, dsn.sourceName , dsn.msgName
答案 0 :(得分:1)
破碎的报告中唯一不同的是我 使用; WITH XMLNAMESPACES(DEFAULT'瓮:hl7-org:v3')
查询XML数据
嗯,这是一个非常重要的唯一的东西 ......
DECLARE @XML XML=
'<root><a>test</a></root>';
SELECT @XML.value('(/root/a)[1]','nvarchar(max)')
按预期返回“test”
WITH XMLNAMESPACES(DEFAULT 'tmpUri')
SELECT @XML.value('(/root/a)[1]','nvarchar(max)')
返回“NULL”
虽然
DECLARE @XML XML=
'<root xmlns="tmpUri"><a>test</a></root>';
WITH XMLNAMESPACES(DEFAULT 'tmpUri')
SELECT @XML.value('(/root/a)[1]','nvarchar(max)')
返回“test”但是没有命名空间提示的同样会返回“NULL”...
省略所有名称空间有一个通用技巧:使用通配符!
SELECT @XML.value('(/*:root/*:a)[1]','nvarchar(max)')