我有2个表Awards_Nominations
和custom_1
,并且我需要用Awards_Nominations.Add14
的串联来更新custom_1.awardNames
列。
条件应具有:
Add1> = GPA
像Add3或'AllMajors'这样的专业
Add2或“高中生”之类的AcademicReq
Add4或“ AllUniversities”之类的大学
我尝试使用update语句内部联接,但是它不会更新。
UPDATE [dbo].[Awards_Nominations]
SET Add14=Add14+','+awardName
from [Awards_Nominations] a
inner join custom_1 on right([Add1],3)>=GPA and (Majors like '%'+Add3+'%' or Majors='AllMajors')
and (AcademicReq like '%'+Add2+'%' or 'High School Student' like '%'+AcademicReq+'%') and (Universities like '%'+Add4+'%' or Universities='AllUniversities')
where n_AwardID=4 and ApprovalStatus='final' and Add1<>''
GO
我的最终目标是实现以下目标:
答案 0 :(得分:0)
使用与多个记录匹配的更新,最后一个更新获胜。源列的值不会更新,以后再用作输入。 (有点像触发器中的“插入”表,该表代表查询之前的数据。)您想将多行中的数据连接为一个值。有很多例子。我自己更喜欢XML。下次需要这样做时,我将尝试STRING_AGG。
How to concatenate text from multiple rows into a single text string in SQL server?