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 apacctwhen 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 OptimizerTG |
 |
|
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. |
 |
|
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 |
 |
|
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'------------EndElseBegin------------ Print 'Records doesn't exist.'------------EndSo tell us what is ur task. |
 |
|
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.refnbrthanks |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-19 : 16:06:21
|
UPDATE atSET Boxnbr = v.DfltBoxFROM apptran atINNER JOIN apdoc adON at.refnbr = ad.refnbrINNER JOIN vendor vON ad.vendid = v.vendidTara Kizeraka tduggan |
 |
|
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.vendidReference : 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 |
 |
|
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 |
 |
|
|