我有两列的表,它们都包含整数值,如下所示:
DocumentUpId RelatedDocId
31608768 31624333
31608768 31624334
31618133 31618117
我正在尝试将它们合并到一个列中,如下所示:
DocumentUpId
31608768
31608768
31618133
31624333
31624334
31624334
我试过这个:
select rel_CTE.DocumentUpId + rel_CTE.DocumentDownId as 'RelatedDocId'
into #temprelations
from RelationsCTE rel_CTE
但它让我连接了值(在这种情况下总和),所以它可能吗?
答案 0 :(得分:9)
UNION ALL
select rel_CTE.DocumentUpId as 'RelatedDocId' from RelationsCTE
union all
select rel_CTE.DocumentDownId from RelationsCTE
答案 1 :(得分:4)
试试这个,
SELECT DocumentUpId as DocumentUpId
FROM RelationsCTE
UNION ALL
SELECT DocumentDownId as DocumentUpId
FROM RelationsCTE