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 |
|
Saeed
Starting Member
39 Posts |
Posted - 2002-07-29 : 21:17:10
|
| declare @count int@count =select count(*) from mytableprint @count |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-07-29 : 21:18:29
|
| set @count =select count(*) from mytableYou could also:select @count=count(*) from mytable |
 |
|
|
Saeed
Starting Member
39 Posts |
Posted - 2002-07-29 : 22:14:02
|
| Thanks..I just found out if I do a select..... and check for @@ROWCOUNTit would tell me how many rows were selected.example:select * from POItem a,#POData b where a.POItemN =b.RowPOItem and a.PurchaseOrderN = b.OldPO if @@ROWCOUNT >0 begin goto skip1 end |
 |
|
|
jasper_smith
SQL Server MVP & SQLTeam MVY
846 Posts |
Posted - 2002-07-30 : 03:57:55
|
| You will find that in longer procedures and those that modify data where you are also checking @@error that it becomes necessary to store your rowcounts and errors in local variables in order to avoid if statements resetting rowcounts. i.e.select * from Northwind..CustomersIf @@error<>0 do somethingIf @@rowcount=0 do somethingIn this pseudo code example @@rowcount will always be 0 becauses it's reset by the If @@error statement. The same applies the other way round i.e. @@error is reset by a succesful If @@rowcount=0 statement.If you trap these "global" variables in local variables you will then be able to act on them accordinglydeclare @err int ; set @err=0declare @cnt int ; set @cnt=0select * from Northwind..Customersselect @err=@@error,@cnt=@@rowcountIf @err<>0 do somethingIf @cnt=0 do somethingHTHJasper Smith |
 |
|
|
|
|
|