I’m trying to update all SQL rows in the [Temp_LTGData] table setting the [CORP_REG_NO] value to the value in another row in the same table where the [CUSTOMER_NUMBER] matches.
Ultimately I need to do this with quite a few columns, does anyone know if this can be done?
I can’t seem to use the LTGSource alias like in a select query 🙁
Update [MandS].[dbo].[Temp_LTGData] LTGSource
Set [CORP_REG_NO] = (SELECT [CORP_REG_NO]
FROM [MandS].[dbo].[Temp_LTGData]
WHERE ([CORP_REG_NO] IS NULL
AND [CUSTOMER_NUMBER] = LTGSource.[CUSTOMER_NUMBER] ))
where [CORP_REG_NO] IS NULL
Thanks for the feedback guys that’s some really awesome stuff, I even learnt some different approaches to this problem (voted for you all).
Try the following to get exactly what you were doing
However, you have a mistake in your query I believe the subquery should be IS NOT NULL.