Updating a table from a table variable

I have an SQL query that declares a table inside it.

Declare @t table(tagname nvarchar(50), Value float, timestamp datetime)

Then I insert some date in this table. Once this is done, I want to update another table (already created) from @t.

Something along the lines of:

UPDATE Optimiser_tagData
SET Optimiser_tagData.value = @t.value
where Optimiser_tagData.tagName = @t.tagName

This obviously does not work, and I get this error:

Must declare scalar variable "@t"

I am sure that I am missing something very light, but I cannot understand it.

+4
source share
1 answer

. Table variable Optimiser_tagData. ( ..)

UPDATE Optimiser
    SET Optimiser.value = t.value
    from Optimiser_tagData Optimiser
    join @t t
    on Optimiser.tagName = t.tagName
+7

Source: https://habr.com/ru/post/1662514/


All Articles