Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting multiple scalar variables from a single row in SQL Server 2008?

In a trigger, I have code like:

SET @var1 = (SELECT col1 FROM Inserted);
SET @var2 = (SELECT col2 FROM Inserted);

Is it possible to write the above in a single line? Something conceptually like:

SET (@var1,@var2) = (SELECT col1,col2 FROM Inserted);

Obviously I tried the above, without success; am I just stuck with the first method?

Even if possible, is that a good idea?

Thanks!

like image 540
johansson Avatar asked Dec 29 '22 02:12

johansson


1 Answers

yes, use first method.

Or...

SELECT
    @var1 = col1
    ,@var2 = col2
FROM
    Inserted;
like image 171
gbn Avatar answered Jan 14 '23 06:01

gbn