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)
 stored procedure help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2006-06-05 : 06:09:49
within my stored procedure how can i run an sql statement

(like select name from names where name is like @myname + %) and if there are no records do select @valid=0

I basically want to know how I can check if the sql returns no recorsds

thansk

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-06-05 : 06:16:43
select @@rowcount
after the statement gives you that information

Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-05 : 06:17:25
use @@rowcount. Place it immediately after your select statement.


select name from names where name is like @myname + %

if @@rowcount = 0 select @valid = 0
else select @valid = 1




KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-05 : 06:18:43



KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-05 : 07:11:56
If you use front end application, then make use of recordset's eof

If rs.eof=true then
--no records
end if

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -