如果一个数据表中查询不到记录,返回值是什么

来源:百度知道 编辑:UC知道 时间:2024/04/28 00:02:12
最简单的例子吧:现在有2个表,表a和b,字段都一样的:姓名,分数
select * a where a from 姓名='张三';
if(查询不到)
select * b where a from 姓名='张三';
假如张三确实在表b中,那a的返回值什么?if括号里面的代码怎么写?

首先楼主的两句语法错误
如果在数据库中首先定义一个变量
decalre @count int
select @count=count(*) from a where 姓名='张三'
if(@count==0)
select * from b where 姓名='张三'
如果在程序中就更简单了
第一个返回一个表,判断该表中有没有数据
即if dt.Rows.count==0
执行第二句

select count(*) into l_cnt from table_a where 姓名='张三';
if l_cnt=0 then
select * from table_b where 姓名='张三';
end if;