主题:  在存储过程中如何判断所得记录是否为空?

5D荣誉版主

职务:普通成员
等级:2
金币:1.0
发贴:515
#12001/6/1 9:39:04
请问在存储过程中执行"select field from table where field=1",如何判断所得记录是否为空。



寂寞菜鸟

职务:普通成员
等级:1
金币:1.0
发贴:173
#22001/6/1 9:57:42
$sql="select field from table where field=1";
$result=mysql_query($sql);
if($result){
..................
}
这是PHP的代码,希望对你有所启发



semon

职务:普通成员
等级:3
金币:1.0
发贴:896
#32001/6/1 10:22:57
if(mysql_error()){
//print out the error message
}
elseif(mysq_num_rows($result)>0){
//no result
}



临时球迷

职务:普通成员
等级:3
金币:10.0
发贴:869
#42001/6/1 11:47:54
asp 的是

qq =" select field from table where field=1"
rs.Open qq,conn,1,1,1
if not rs.Eof and not rs.Bof then
......
else
......
end if
re.close

或者用
qq= "select count(field) as t from table where field=1"
rs.Open qq,conn,1,1,1
test_number=rs("t")
if if test_number<>0 then
......
else
......
end if

HIHI

仅供参考



5D荣誉版主

职务:普通成员
等级:2
金币:1.0
发贴:515
#52001/6/1 23:26:27
在asp里我也会,我是说在sql server 的存储过程里用sql 语句判断,
难道只有select count(*) 先吗?



绿茶

职务:普通成员
等级:8
金币:10.0
发贴:19267
#62001/6/2 9:01:22
对,好像只能用(select count(*)来判断是否值为真,其它好像在存储过程中没有办法来判断值是否为真。你只能用
if (select count(*) form field where field=1
//do something
else begin
//do something
end