sql-server-2008 – 在此查询中使用Blob列要求查询主题必须具有密钥或唯一索引

我有以下代码:

SELECT  boo_event 'Orden de Trabajo' ,STUFF((SELECT ', ' + CAST(boo_person AS VARCHAR(100)) [text()]    
    FROM R5BOOKEDHOURS 
    WHERE boo_event = t.boo_event
    FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,1,' ') Empleados , STUFF((SELECT ', ' + CAST(boo_hours AS VARCHAR(100)) [text()]       
    FROM R5BOOKEDHOURS 
    WHERE boo_event = t.boo_event
    FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,1,' ') Horas
    FROM R5BOOKEDHOURS t
    GROUP BY boo_event

它在SQL Server Studio上完美运行,但是当我尝试在COGNOS Reporting Studio上使用它时,我收到此错误:

– 在此查询中使用Blob列要求查询主题必须具有键或唯一索引 –

我不确定这个工具是否只是一个错误,或者我们可以修改一些代码.

最佳答案 将NVARCHAR(MAX)更改为NVARCHAR(4000):

SELECT  boo_event 'Orden de Trabajo' ,STUFF((SELECT ', ' + CAST(boo_person AS VARCHAR(100)) [text()]    
FROM R5BOOKEDHOURS 
WHERE boo_event = t.boo_event
FOR XML PATH(''), TYPE).value('.','NVARCHAR(4000)'),1,1,' ') Empleados , STUFF((SELECT ', ' + CAST(boo_hours AS VARCHAR(100)) [text()]       
FROM R5BOOKEDHOURS 
WHERE boo_event = t.boo_event
FOR XML PATH(''), TYPE).value('.','NVARCHAR(4000)'),1,1,' ') Horas
FROM R5BOOKEDHOURS t
GROUP BY boo_event;
点赞