patternsqlModerate
Direct the OUTPUT of an UPDATE statement to a local variable
Viewed 0 times
localtheupdatestatementoutputdirectvariable
Problem
I would like to do this :
Is this even possible? I know I can declare a local table variable and direct the output there but I would prefer to skip it if possible
DECLARE @Id INT;
UPDATE Logins
SET SomeField = 'some value'
OUTPUT @Id = Id
WHERE EmailAddress = @EmailAddress -- this is a parameter of the sprocIs this even possible? I know I can declare a local table variable and direct the output there but I would prefer to skip it if possible
Solution
No, because you are potentially
You need to output into a
OUTPUTting multiple rows, which wouldn't fit into a scalar variable.You need to output into a
@Table variable or declared table to handle multiple rows of output.Context
StackExchange Database Administrators Q#22684, answer score: 15
Revisions (0)
No revisions yet.