Samantha J T Star
Samantha J T Star

Reputation: 32758

How can I select multiple values into locally declared variables in a SQL Server Stored Proc?

Here's what I have:

DECLARE Name  VARCHAR(20)
DECLARE Pass  INT
SELECT  Name,
        Pass,
FROM    AdminTest
WHERE   TestId = @TestId

But this selects and reports.

How can I have the values stored into the local variables?

Upvotes: 0

Views: 33

Answers (1)

Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35780

It is incorrect declaration of variables. You should declare variables using @. Do something like this:

DECLARE @Name  VARCHAR(20)
DECLARE @Pass  INT
SELECT  @Name = Name,
        @Pass = Pass,
FROM    AdminTest
WHERE   TestId = @TestId

Upvotes: 4

Related Questions