Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to store the result of this sql query in variable @a. The result contains 17 rows. How to edit this code in order to store the rows in @a?
@a
declare @a uniqueidentifier select EnrollmentID into @a from Enrollment
You cannot store 17 values inside a scalar variable. You can use a table variable instead.
This is how you can declare it:
DECLARE @a TABLE (id uniqueidentifier)
and how you can populate it with values from Enrollment table:
Enrollment
INSERT INTO @a SELECT EnrollmentID FROM Enrollment
Add a comment
You should declare @a as a Table Variable with one column of type unique identifier as follows:
DECLARE @a TABLE (uniqueId uniqueidentifier); INSERT INTO @a SELECT EnrollmentID FROM Enrollment;
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.