从字符串转换为唯一标识符 SQL Server 2014 时转换失败



这是我的SQL查询。执行此查询时,我收到上述错误

WITH Results_CTE AS (select Top 20 ROW_NUMBER() OVER (ORDER BY KeyId desc) AS SNo,* from(select * from (  select ps.Id as KeyId,dps.Id as SettingId,dps.DocumentType,dps.DocumentProcessingType,null as Description,null as Link
            from [ParttimerSalary] ps inner join [ParttimerEmployee] pe on pe.Id = ps.ParttimerEmployeeId 
            inner Join [DocumentProcessingSetting] dps on dps.Step = ps.Step and dps.KeyId = pe.ParttimerType and 
            (dps.RoleId = 'e218e9e0-d51d-45b4-9380-77f43ac50f0d' or dps.UserId = '1967681a-7d64-486e-99a8-4b58746cef81') and dps.DocumentType = 2 union all 
            Select 'Incident/service is assigned for you' as [Description],'#/it/incidentsupport/' as Link,0 as Id,0 as SettingId,0 as DocumentType,0 as DocumentProcessingType from Incident where IncidentStatus = 2 and SupportById = '1967681a-7d64-486e-99a8-4b58746cef81'
            )wrapped) listing ORDER BY KeyId desc) SELECT * FROM Results_CTE WHERE SNo >= 0 AND SNo <=20

任何帮助将不胜感激。谢谢

使用 Union 时,所有数据类型都应在两个选择元素中匹配。

  • 附言。作为 KeyId 的 Id 是唯一标识符,而"为您分配事件/服务"作为 [说明] 是导致错误的字符串。
实际上

,我已经更改了联合关键字之后从表中选择列的顺序,因为在联合期间,我们需要管理两个表字段的顺序,数据类型等问题解决了。无论如何,谢谢

最新更新