Can you help me to solve this error
The type of column "nvrchildgender" conflicts with the type of other columns specified in the UNPIVOT list.
Table structure:
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]
Query:
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
I cannot to able to run this query i think some cast problem pls resolve.