如何将4列数据合并为一列?

时间:2021-07-31 17:03:46

In SQL 2008 Im trying to combine the data from 4 columns into a single column. I have searched and tried several different things but none have worked. My latest attempt has been :

在SQL 2008中,我试图将来自4列的数据合并到一个列中。我搜索并尝试了几种不同的东西,但都没有。我的最新尝试是:

SELECT [2012 Notes] + [2012 STEPS TAKEN TO REMEDY ISSUES] + [2013 NOTES] + [2013 STEPS TAKEN TO REMEDY ISSUES] AS 'ConcatNotes'
FROM ECRSurvey

UPDATE ECRSurvey Set UserNotes = 'ConcatNotes'

This does not work though. Can someone tell me the proper way to do this? Im basically trying to take 4 columns and trying to combine that data into the UserNotes field.

但这不起作用。有人能告诉我这样做的正确方法吗?我基本上试图采取4列,并尝试将这些数据组合到UserNotes字段中。

3 个解决方案

#1


2  

That should work - you probably have some NULLS.

这应该工作 - 你可能有一些NULLS。

try

SELECT ISNULL([2012 Notes],'') + ISNULL([2012 STEPS TAKEN TO REMEDY ISSUES],'') + ISNULL([2013 NOTES],'') + ISNULL([2013 STEPS TAKEN TO REMEDY ISSUES],'') AS 'ConcatNotes'
FROM ECRSurvey

or to update

或者更新

UPDATE ECRSurvey Set UserNotes = ISNULL([2012 Notes],'') + ISNULL([2012 STEPS TAKEN TO REMEDY ISSUES],'') + ISNULL([2013 NOTES],'') + ISNULL([2013 STEPS TAKEN TO REMEDY ISSUES],'')

#2


1  

If any of those columns contain NULLs, the result will be NULL. You'll want to coalesce or isnull checks on the fields.

如果其中任何列包含NULL,则结果将为NULL。你想要对这些字段进行合并或空洞检查。

#3


0  

Please try following query:

请尝试以下查询:

Update ECRSurvey
set UserNotes =[2012 Notes] + [2012 STEPS TAKEN TO REMEDY ISSUES] + [2013 NOTES] + [2013 STEPS TAKEN TO REMEDY ISSUES]

#1


2  

That should work - you probably have some NULLS.

这应该工作 - 你可能有一些NULLS。

try

SELECT ISNULL([2012 Notes],'') + ISNULL([2012 STEPS TAKEN TO REMEDY ISSUES],'') + ISNULL([2013 NOTES],'') + ISNULL([2013 STEPS TAKEN TO REMEDY ISSUES],'') AS 'ConcatNotes'
FROM ECRSurvey

or to update

或者更新

UPDATE ECRSurvey Set UserNotes = ISNULL([2012 Notes],'') + ISNULL([2012 STEPS TAKEN TO REMEDY ISSUES],'') + ISNULL([2013 NOTES],'') + ISNULL([2013 STEPS TAKEN TO REMEDY ISSUES],'')

#2


1  

If any of those columns contain NULLs, the result will be NULL. You'll want to coalesce or isnull checks on the fields.

如果其中任何列包含NULL,则结果将为NULL。你想要对这些字段进行合并或空洞检查。

#3


0  

Please try following query:

请尝试以下查询:

Update ECRSurvey
set UserNotes =[2012 Notes] + [2012 STEPS TAKEN TO REMEDY ISSUES] + [2013 NOTES] + [2013 STEPS TAKEN TO REMEDY ISSUES]