Getting "output messages" from the SQL command line (SQL Server)

I execute several discrete queries in one batch against SQL Server. For instance:

update tableX set colA = 'freedom';

select lastName from customers;

insert into tableY (a, b, c) values ​​(x, y, z);

Now I want to write the result to a DataSet (from the select statement), which is simple enough to do ... but how do I also grab the meta response from this command, similar to the way the Query Analyzer / SQL Mgt Studio does this when it displays the tab " Messages, "and duplicates something similar to:

(1 Row affected)
(2 Rows Updated)
+3
source share
3 answers

, @@rowcount. , , , ,

declare @rowsAffected int, @error int

select * from sometable
     select @rowsAffected = @@rowcount, @error = @@error

if @@error <> 0 goto errorCleanup
+3

, @@ROWCOUNT - , SET NOCOUNT ON, () - , , ...

(, ), :

  • SELECT

+1
source

All Articles