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
?
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:
INSERT INTO @a
SELECT EnrollmentID FROM Enrollment
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With