Please push on the right decision, I’ve been fighting for the second day, I tried a lot, one of the most successful was the use of MERGE , but either I wrote crookedly or it didn’t work.

I need to create a temporary table with certain columns and attach one new column one by one (depending on certain tasks)

Below is the code I wrote for the sample. I tried to add a column from the table on the basis of which I created a temporary one. But there is an error

multi-part identifiear "tempTable.column_new"

one)

  select col1, col2, ACCOUNT_RC into #account from TABLE1 

2)

  alter table #account add ACCOUNT_RC_izmenen numeric(18,0) 

3)

  MERGE #account AS tempTable USING (SELECT ACCOUNT_RC + 1000000, ACCOUNT_RC from TABLE1) as source (ACCOUNT_RC_izmenen, ACCOUNT_RC) ON (tempTable.ACCOUNT_RC = source.ACCOUNT_RC) WHEN MATCHED THEN UPDATE SET tempTable.column_new = source.ACCOUNT_RC_izmenen ; 
  • duck added then you are ACCOUNT_RC_izmenen , but why are you applying to the column_new field? - teran
  • For some reason, it seems to me that this merge similar to a simple update #account set ACCOUNT_RC_izmenen = ACCOUNT_RC_izmenen + 1000000 - teran
  • oh yes this is a typo .. where adding a column is not ACCOUNT_RC_izmenen numeric (18,0) and column_new numeric (18,0) - Pavel Burunin
  • similar, but this is a test request, only for testing the technology. then I will add columns from other tables - Pavel Burunin
  • just specify .... UPDATE SET column_new = source... without tempTable , because it swears. - teran

0