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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 @@rowcount returns 0

Author  Topic 

sunpalozzi
Starting Member

9 Posts

Posted - 2005-12-19 : 14:17:28
hello all,
this is my script:
DECLARE Vendors CURSOR FOR
SELECT vendid, DfltBox
FROM Vendor
WHERE rtrim(ltrim(vend1099)) ='1'
order by apacct
when i do @@rowcount, it returns 0, it will return the right number if I don't use the cursor. How do I check if the return dataset is empty?? thanks.
Sunpalozzi

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-12-19 : 14:25:37
All you've done is declare your cursor so your @@rowcount should be zero. Why don't you explain what you're trying to accomplish. I'm quite certain that you that you don't need to use cursors at all.

Be One with the Optimizer
TG
Go to Top of Page

sunpalozzi
Starting Member

9 Posts

Posted - 2005-12-19 : 14:35:13
TG,
I am trying to use the @@rowcount to see if any record returned from my query.
thanks.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-12-19 : 14:45:31
quote:
Originally posted by sunpalozzi

TG,
I am trying to use the @@rowcount to see if any record returned from my query.
thanks.



you need to select @@rowcount right after the query, otherwise you will return a 0. see this article for more details on the global variables in SQL Server.

http://www.sqlteam.com/item.asp?ItemID=306




-ec
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2005-12-19 : 15:34:02
quote:
Originally posted by sunpalozzi
I am trying to use the @@rowcount to see if any record returned from my query.



And after that what r u going to do?
May be u can do the same task, without the cursor - more efficiently.

eg:
if Exists (SELECT vendid, DfltBox FROM Vendor WHERE rtrim(ltrim(vend1099)) '1'
Begin
------------
Print 'Record(s) Exists'
------------
End
Else
Begin
------------
Print 'Records doesn't exist.'
------------
End

So tell us what is ur task.
Go to Top of Page

sunpalozzi
Starting Member

9 Posts

Posted - 2005-12-19 : 15:58:41
here is what I need to accomplish:
3 tables: vendor, apdoc and aptran.
I need to do is: for all the 1099 vendors, I need to update the Boxnbr in the apptran table with DfltBox in the vendor table. there is not direct link between vendor and aptran tables.

vendor.vendid = apdoc.vendid
apdoc.refnbr = aptran.refnbr


thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-12-19 : 16:06:21
UPDATE at
SET Boxnbr = v.DfltBox
FROM apptran at
INNER JOIN apdoc ad
ON at.refnbr = ad.refnbr
INNER JOIN vendor v
ON ad.vendid = v.vendid

Tara Kizer
aka tduggan
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2005-12-19 : 16:19:49
Check this

UPDATE apptran
SET Boxnbr = vendor.DfltBox
FROM apdoc
INNER JOIN aptran ON apdoc.refnbr = aptran.refnbr
INNER JOIN vendor ON vendor.vendid = apdoc.vendid

Reference : BOL Search -- "Changing Data Using the FROM Clause"

But what did u try to do with a cursor ? @@RecordCount ?
Don't worry if u resolved ur issue, but learn more about cursors, update methods etc
Go to Top of Page

sunpalozzi
Starting Member

9 Posts

Posted - 2005-12-19 : 16:53:52
thank you all very much for all the replies. I will look into the reference Srinika provided above. thank you again.
Sunpalozzi
Go to Top of Page
   

- Advertisement -