1

在 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'

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

4

3 回答 3

2

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

尝试

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

或更新

UPDATE ECRSurvey Set UserNotes = ISNULL([2012 Notes],'') + ISNULL([2012 STEPS TAKEN TO REMEDY ISSUES],'') + ISNULL([2013 NOTES],'') + ISNULL([2013 STEPS TAKEN TO REMEDY ISSUES],'')
于 2013-10-22T15:08:42.277 回答
1

如果这些列中的任何一个包含 NULL,则结果将为 NULL。您需要对字段进行合并或 isnull 检查。

于 2013-10-22T15:08:35.383 回答
0

请尝试以下查询:

Update ECRSurvey
set UserNotes =[2012 Notes] + [2012 STEPS TAKEN TO REMEDY ISSUES] + [2013 NOTES] + [2013 STEPS TAKEN TO REMEDY ISSUES]
于 2013-10-22T15:08:42.847 回答