sql update variable code example

Example 1: update in sql

--update query example
 UPDATE table_name
 SET column1 = value1, column2 = value2, ...
 WHERE condition;

Example 2: updating values in sql

//to update value

UPDATE students SET course_id = 102
WHERE last_name = 'Jones'; -> 
                 if there is no condition it will update all!

Example 3: t-sql update table variale

UPDATE @searchResult
SET [record_id] = r.[record_id], 
    [record_name] = r.[record_name]
FROM @searchResult SR
CROSS APPLY (
    SELECT TOP 1 *
    FROM [records]
    WHERE [record_name] LIKE [name_template]   -- Your wish, but do you really need LIKE matching??
    ORDER BY [record_id] DESC
) AS r;

Tags:

Sql Example