I have got any TSQL UPDATE statement and I'd like to know the number of rows that would be affected or the @@ROWCOUNT before really executing the updates.
I think I could replace the UPDATE part of the query with a SELECT COUNT(1), but it seems to me there should be an easier way. Is there an easier way?
If there is no easy solution in SQL, a solution in .NET/C# would be ok for me too; I'm using System.Data.SqlClient.SqlCommand to execute the command anyway. I'm using MSSQL 2008.
Example:
create table T (
A char(5),
B int
)
insert into T values ('a', 1)
insert into T values ('A', 1)
insert into T values ('B', 2)
insert into T values ('X', 1)
insert into T values ('D', 4)
-- I do not want to execute this query
-- update T set A = 'X' where B = 1
-- but I want ot get the @@ROWCOUNT of it, in this case
-- the wanted result would be 3.