I am wanting to execute my select statement, but also store the returned row count into a variable. This is how my DDL is set-up, how can I store the row count from my Select statement in my variable@returnedrows
Declare @returnedrows int;
Insert Into pinkpurplegreen (field1, field2, field3, field4, field5)
Select field1, field2, field3, field4, field5
FROM blue
Select * FROM pinkpurplegreen
asked Oct 12, 2016 at 12:12
1 Answer 1
You would need to select the @@ROWCOUNT variable
CREATE TABLE dba_152082 (field1 int NOT NULL);
INSERT INTO dba_152082 (field1) VALUES (1),(1), (2);
DECLARE @numberofrows int;
SELECT * FROM dba_152082;
SELECT @numberofrows = @@ROWCOUNT;
PRINT @numberofrows;
DROP TABLE dba_152082;
You should be able to verify the value of your variable in the messages tab after you run that.
answered Oct 12, 2016 at 12:24
Explore related questions
See similar questions with these tags.
lang-sql