你能帮我解决这个错误吗
“nvrchildgender”列的类型与 UNPIVOT 列表中指定的其他列的类型冲突。
表结构:
CREATE TABLE [dbo].[tblHRIS_ChildDetails](
[intCHID] [int],
[intSID] [int] NOT NULL,
[nvrChildname] [nvarchar](250) NULL,
[nvrChildGender] [nvarchar](50) NULL,
[dttChildDOB] [datetime] NULL,
[nvrnominee] [nvarchar](50) NULL,
[nvrChildOccupation] [nvarchar](250) NULL,
[dttCreatedon] [datetime] NULL,
[dttModifiedOn] [datetime] NULL,
[nvrModifiedby] [nvarchar](50) NULL
) ON [PRIMARY]
询问:
select *
from
(
select value, col+'_'+cast(rn as varchar(10)) col
from
(
select nvrchildname,
nvrchildgender,
convert(nvarchar(10), dttchildDOB, 120) dttchildDOB,
nvrchildoccupation,
row_number() over(partition by intsid order by intCHID) rn
from tblHRIS_ChildDetails
where intsid = 463
) src
unpivot
(
value
for col in (nvrchildname, nvrchildgender, dttchildDOB, nvrchildoccupation)
) unpiv
) src1
pivot
(
max(value)
for col in ([nvrchildname_1], [nvrgender_1],
[dttchildDOB_1], [occupation_1],
[nvrchildname_2], [nvrgender_2],
[dttchildDOB_2], [occupation_2])
) piv
我无法运行此查询,我认为请解决一些演员问题。