SQL 语句

[复制链接]
查看11 | 回复3 | 2008-11-4 15:13:53 | 显示全部楼层 |阅读模式
select * from customer weherename=‘传来的值’
and id=‘传来的值’ ;
我想做的是 如果传来的name是空的话就只查询 id 的值如果 都为空 就全查出来
在线等
这是是在 ibtais里面的不能用 java代码

大家想办法啊

回复

使用道具 举报

千问 | 2008-11-4 15:13:53 | 显示全部楼层
string sql="select * from customer ";if(name!=""and id!="" ){ sql+=" where name='"+传来的值+"'id='"+传来的值+"'";}else if(name!=""){ sql+=" where name='"+传来的值+"'";}else if(id!="" ){sql+=" where id='"+传来的值+"'";}这样比较灵活,方便日后维护...
回复

使用道具 举报

千问 | 2008-11-4 15:13:53 | 显示全部楼层
c# code: string sqlstr="select * from customer where 1=1"; if (name!="") { sqlstr+=" and name='"+name+"'"; } if (id!="") { sqlstr+=" and id="+id; }...
回复

使用道具 举报

千问 | 2008-11-4 15:13:53 | 显示全部楼层
dim a,bif a"" then a=" and name=‘传来的值 "end if if b"" then b=" and id=‘传来的值’"end if sql="select * from customer where 1=1" & a & b...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行