How To Get Number Of Rows Inserted By a Transaction In MSSQL

I was struggling with when I wan to get the status of the number of the rows that I have inserted. That why I would like to share what I face to everyone

let's me give a short description before jump to it

 
@@ROWCOUNT will going to show the exact number of rows that affected by the last SQL statement, it is best way to capture it into a local variable following the command in question, as its value will change the next time you look at it:

DECLARE @NRows int
DECLARE @MTable table (cl1 int, cl2 int)
INSERT INTO @MTable (cl1, cl2) select 1,2 union select 3,4
SELECT @NRows=@@ROWCOUNT
SELECT @NRows AS NRows,@@ROWCOUNT AS [NUMBEROFROW]


As A Result should be like this 

 

I hope this is helpful 
Share on Google Plus
If you think this article is helpful don't froget share it to your friends.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment