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 |
|
Kristen
Test
22859 Posts |
Posted - 2004-11-05 : 07:43:39
|
I wasn't expecting this to set @@ROWCOUNT=1 :-(DECLARE @MyPK_ID intSELECT @MyPK_ID =( SELECT TOP 1 MyPK_ID FROM dbo.MyTable WHERE MyOtherColumn = 'NeverMatchThis' ORDER BY MyCreateDate, MyPK_ID -- Oldest first)SELECT [@MyPKID]=@MyPKID, [@@ROWCOUNT]=@@ROWCOUNTResult is:@MyPKID @@ROWCOUNT ------- ----------- NULL 1 Kristen |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2004-11-05 : 07:50:34
|
| Ummmmmm, why not? It's got two SELECT statements in it.This should blow your mind:print @@rowcountdeclare @a datetimeprint @@rowcountset @a=getdate()print @@rowcountselect @a=getdate()print @@rowcountselect @a=getdate() from sysobjectsprint @@rowcount |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-11-05 : 08:38:43
|
| Yeah, so I need to try harder. Class is always the same :-(But I spent a good age relying on the @@ROWCOUNT falling to 0 [which never happened] where there was no more to process, instead of checking that the selected value was coming back NULL. Je suis un plonker!Kristen |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-11-05 : 08:42:55
|
| I guessed the second one wrongly ...print @@rowcount -- 0 or n - depending on previous taskdeclare @a datetimeprint @@rowcount -- No value hereset @a=getdate()print @@rowcount -- 1 - same as a SELECTselect @a=getdate()print @@rowcount -- Dittoselect @a=getdate() from sysobjectsprint @@rowcount -- COUNT(*) from sysobjectsKristen |
 |
|
|
|
|
|