Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sapator
Constraint Violating Yak Guru
462 Posts |
Posted - 2010-03-17 : 00:21:38
|
Hi.I'm trying to print the @@rowcount of a delete sp operation but i only get zero as resultdelete from operations where operations.id in(SELECT operations.id FROM drugsoperations RIGHT JOIN operations ON drugsoperations.operationsid = operations.idwhere drugsoperations.id is null)if @@rowcount > 0Beginset @operationscount=@@rowcountPrint @operationscountEndElse Beginreturn 99End @operationscount declared as bigint |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-17 : 00:33:01
|
@@rowcount only available immediately after the query. It is reset after the if statementAssign to the variable immediately after the querydelete from operations where operations.id in(SELECT operations.id FROM drugsoperations RIGHT JOIN operations ON drugsoperations.operationsid = operations.idwhere drugsoperations.id is null)set @operationscount=@@rowcountif @@operationscount> 0BeginPrint @operationscountEndElse Beginreturn 99End KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2010-03-17 : 00:33:23
|
You need to get the @@rowcount into a variable before you use it in any logic. The value of @@rowcount is reset after every statement. delete from operations where operations.id in(SELECT operations.id FROM drugsoperations RIGHT JOIN operations ON drugsoperations.operationsid = operations.idwhere drugsoperations.id is null)If @@rowcount > 0 Select @operationscount = @@rowcountelse Select @operationscount = 99return @operationscount Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
sapator
Constraint Violating Yak Guru
462 Posts |
Posted - 2010-03-17 : 00:33:56
|
| Ok, i'm trying right now, will let you know... |
 |
|
|
sapator
Constraint Violating Yak Guru
462 Posts |
Posted - 2010-03-17 : 00:37:46
|
| Worked nicely.Thanks! |
 |
|
|
|
|
|