本文介绍了如何在sql中使用unpivot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个错误...
please help me to solve this error...
SELECT
*
FROM
(
SELECT t.N_Srno, t.N_Visitorder,
t.N_workedwithmcr, t.N_MCLshow,
t.N_MtpSbmMcr, t.N_MtpSbmDcr,
t.N_MtpappMcr, t.N_MtpappDcr,
t.N_Stpsubmitiondcr, t.N_PriTargetOn,
t.N_Doctortime, t.n_mscexpences,
t.N_SecTargeton, t.N_mtpsubarea,
t.c_prefixTN, t.c_prefixGDN,
t.N_year, t.N_secvalue,
t.N_Stpsubmitionmcr, t.N_TargItemBrand,
t.n_closingday, t.n_pri_inv_imp,
t.c_tacode, t.c_dacode, t.c_monthly
FROM tbl_controlpanel_mst as t
) AS SourceTable
UNPIVOT
(
Value FOR Col IN (N_Srno, N_Visitorder,
N_workedwithmcr, N_MCLshow,
N_MtpSbmMcr, N_MtpSbmDcr,
N_MtpappMcr, N_MtpappDcr,
N_Stpsubmitiondcr, N_PriTargetOn,
N_Doctortime, n_mscexpences,
N_SecTargeton, N_mtpsubarea,
c_prefixTN, c_prefixGDN,
N_year, N_secvalue,
N_Stpsubmitionmcr, N_TargItemBrand,
n_closingday, n_pri_inv_imp,
c_tacode, c_dacode,
c_monthly
)
) AS unpvt
我收到错误
I am getting error of
Msg 8167, Level 16, State 1, Line 39
The type of column "N_Visitorder" conflicts with the type of other columns specified in the UNPIVOT list.
请告诉我..
please tell me..
推荐答案
SELECT
*
FROM
(
SELECT t.N_Srno, t.N_Visitorder,
t.N_workedwithmcr, t.N_MCLshow,
t.N_MtpSbmMcr, t.N_MtpSbmDcr,
t.N_MtpappMcr, t.N_MtpappDcr,
t.N_Stpsubmitiondcr, t.N_PriTargetOn,
t.N_Doctortime, t.n_mscexpences,
t.N_SecTargeton, t.N_mtpsubarea,
t.c_prefixTN, t.c_prefixGDN,
t.N_year, t.N_secvalue,
t.N_Stpsubmitionmcr, t.N_TargItemBrand,
t.n_closingday, t.n_pri_inv_imp,
t.c_tacode, t.c_dacode, t.c_monthly
FROM tbl_controlpanel_mst as t
) AS SourceTable
UNPIVOT
(
Value FOR Col IN (N_Visitorder,
N_workedwithmcr, N_MCLshow,
N_MtpSbmMcr, N_MtpSbmDcr,
N_MtpappMcr, N_MtpappDcr,
N_Stpsubmitiondcr, N_PriTargetOn,
N_Doctortime, n_mscexpences,
N_SecTargeton, N_mtpsubarea,
N_year, N_secvalue,
N_Stpsubmitionmcr, N_TargItemBrand,
n_closingday, n_pri_inv_imp
)
) AS unpvt
这篇关于如何在sql中使用unpivot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!