Reputation: 17439
I use the following t-sql code for assign to variable a value obtained from select statement
DECLARE @cfMitt nvarchar(16)
SET @cfMitt = (SELECT CfMittente
FROM Messaggi
WHERE IDMessaggio = @IDMessaggio)
If I want use multiple assignement I try with the following code, but something is wrong:
DECLARE @cfMitt nvarchar(16)
DECLARE @cfDest nvarchar(16)
SET @cfMitt, @cfDest= (SELECT CfMittente, CfDestinatario
FROM Messaggi
WHERE IDMessaggio = @IDMessaggio)
Where is the error?
Upvotes: 0
Views: 3535
Reputation: 33839
Variable declaration can also be;
DECLARE @V1 VarType, @V2 VarType,...
Assignment;
SELECT @V1 = C1, @V2 = C2,...@Vn = Cn
FROM [Table]
WHERE Conditions
Upvotes: 1
Reputation: 51514
Set
only assigns one value at a time.
You should use
SELECT @cfMitt = CfMittente,
@cfDest = CfDestinatario
FROM Messaggi
WHERE IDMessaggio = @IDMessaggio
Upvotes: 6