请教sql语句
如果一条记录的某个字段有数据(不为空),则显示Y,否则显示N。
例如:
库中记录为:
id cash
1 100
2
3 200
经过查询并显示的状态为:
id cash
1 Y
2 N
3 Y
问题点数:100、回复次数:11Top
1 楼Yang_(扬帆破浪)回复于 2002-06-10 14:02:35 得分 100
select id,case when cash is null then 'N' else 'Y' end as cash
from tablename
Top
2 楼IronPromises(铁诺)回复于 2002-06-10 14:04:13 得分 0
select id,case when isnull(cash,0) > 0 then 'Y' else 'N' end cash
from yourTable
Top
3 楼IronPromises(铁诺)回复于 2002-06-10 14:05:10 得分 0
:(
Top
4 楼dingwei(小丁子)回复于 2002-06-10 14:07:31 得分 0
同意楼上的楼点Top
5 楼qybao(阿宝)回复于 2002-06-10 14:07:39 得分 0
来晚了,楼上都说了Top
6 楼VB_support(爱上有夫之妇)回复于 2002-06-10 14:10:48 得分 0
select id,case when cash is null then 'N' when cash = '' then 'N' else 'Y' end as cash
from tablenameTop
7 楼gzhughie(hughie)回复于 2002-06-10 17:00:36 得分 0
select id,case when cash>'' then 'y' ELSE 'N' end as cash
from tablenameTop
8 楼banweihui(KBoy)回复于 2002-06-10 17:29:57 得分 0
唉,网络不通的结果,大差不差,祝你好运!Top
9 楼gzhughie(hughie)回复于 2002-06-10 18:05:40 得分 0
最简单的写法
select id,case when cash >'' then 'Y' else 'N' end as cash
from tablename
Top
10 楼ourai()回复于 2002-06-10 18:56:05 得分 0
解决了,谢谢各位了。Top
11 楼banweihui(KBoy)回复于 2002-06-11 17:56:53 得分 0
不给分吗!Top




