1

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

6

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

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.

Ask question

Explore related questions

See similar questions with these tags.