How can you get @@error and @@rowcount at the same time?

Answers were Sorted based on User's Feedback



How can you get @@error and @@rowcount at the same time?..

Answer / laxman

SELECT @RC = @@ROWCOUNT
SELECT @ER = @@ERROR
if we use above statements then @@error will be reset with
0.
i think right one is

select @er=@@error,@rc=@@rowcount

Is This Answer Correct ?    31 Yes 1 No

How can you get @@error and @@rowcount at the same time?..

Answer / gunasekaran k.j

SELECT @@Rowcount as rwCount, @@Error as Er

Is This Answer Correct ?    15 Yes 2 No

How can you get @@error and @@rowcount at the same time?..

Answer / pankaj

If @@Rowcount is checked after Error checking statement then
it will have 0 as the value of @@Recordcount as it would
have been reset. And if @@Recordcount is checked before the
error-checking statement then @@Error would get reset. To
get @@error and @@rowcount at the same time do both in same
statement and store them in local variable. SELECT @RC =
@@ROWCOUNT, @ER = @@ERROR

Is This Answer Correct ?    6 Yes 0 No

How can you get @@error and @@rowcount at the same time?..

Answer / binoo tiku

@@error variable shows the error number of the last
T-SQL error

@@rowcount variable gives the number of rows affected by
the most recent SQL statements.

Is This Answer Correct ?    9 Yes 7 No

How can you get @@error and @@rowcount at the same time?..

Answer / ramakrishna

this is not answer

Is This Answer Correct ?    4 Yes 3 No

How can you get @@error and @@rowcount at the same time?..

Answer / raji

@@error - displays the error number of last T-Sql statement
@@rowcount - displays the total row count of last T-Sql
statement

Is This Answer Correct ?    3 Yes 2 No

How can you get @@error and @@rowcount at the same time?..

Answer / sachin rakshe

If @@Rowcount is checked after Error checking statement then
it will have 0 as the value of @@Recordcount as it would
have been reset. And if @@Recordcount is checked before the
error-checking statement then @@Error would get reset. To
get @@error and @@rowcount at the same time do both in same
statement and store them in local variable. SELECT @RC =
@@ROWCOUNT, @ER = @@ERROR

Is This Answer Correct ?    0 Yes 0 No

How can you get @@error and @@rowcount at the same time?..

Answer / yjreddy

select @@ROWCOUNT
it will give the no of rows affected by last sql statement
select @@ERROR
it will display the error number for last sql statement

Is This Answer Correct ?    0 Yes 3 No

How can you get @@error and @@rowcount at the same time?..

Answer / ramakrishna

DECLARE @RC int
DECLARE @ER int

INSERT INTO T(Cal1,Col2..)
SELECT ColX,ColY..
FROM T1

SELECT @RC = @@ROWCOUNT
SELECT @ER = @@ERROR

Is This Answer Correct ?    3 Yes 16 No

Post New Answer

More SQL Server Interview Questions

CREATE TABLE [dbo].[HPMS_CompetencyTypes](CompetencyType varchar(50) ) go create trigger hpms_create_Insert on HPMS_CompetencyTypes for insert as if Exists ( select * from [HPMS_CompetencyTypes] where CompetencyType=(select * from [HPMS_CompetencyTypes])) begin Rollback tran Raiserror ('duplicate value',12,6) go insert HPMS_CompetencyTypes (CompetencyType) values ('new') I'm new to trigger can any one tell me where is the issue. Please.

2 Answers  


What is the difference between char, varchar and nvarchar?

0 Answers  


When do we use the UPDATE_STATISTICS command?

4 Answers   Deutsche Telekom AG,


What is perspective, have you ever created perspective? : sql server analysis services, ssas

0 Answers  


Tell me what is log shipping?

0 Answers  






what is database replicaion? : Sql server database administration

0 Answers  


i have 4 tables.. T1, T2, T3, T4.. these tables have the same structure and they store the information entered in different years.. T1 stored 2002, T2 stored 2003, T3 stored 2004 and T4 stored 2005.. i want to copy contents in T1 to T2, T2 to T3, T3 to T4 and T4 to T1.. how do i do that? Temp tables cannot be used..

4 Answers  


What is transaction ? Give me one example.

11 Answers   Melstar, Wipro,


What is the default Port No on which SQL Server listens?

0 Answers  


How to find table changes in sql server?

0 Answers  


Explain indexed view?

1 Answers  


how can a database be repaired? : Sql server administration

0 Answers  


Categories