用SQL语句解决?!(50分)

  • 主题发起人 主题发起人 jobsxy
  • 开始时间 开始时间
J

jobsxy

Unregistered / Unconfirmed
GUEST, unregistred user!
数据库表定义如下:

A01 字符
A011 ..
A012 ..
A013 ..
A014 ..

现有一个要求,如果A01字段为'XXX'时,则显示A011--A014中的某个字段,即A011为空时显示
A012,如果A012为空则显示A013,以此类推....

需用SELECT ..... FROM MYDATA来实现。

(在录入时已经控制住,A011-A014只能有一个字段有数据)
 
select * from mydata where A01<>''
 
楼上,可能是我表达有问题,您没理解我的意思,我是希望这样:

if A01='XXX' then begin
if a011<> nil then 'select a011 from mydata'
else
if a012<> nil then 'select a012 from mydata'
else
if a013<> nil then 'select a013 from mydata'
else
if a014<> nil then 'select a014 from mydata'
end;
 
用计算字段,在QUERY的计算事件中进行判断。
 
难道不能用SQL一句搞定吗?
(不好用计算字段,因为这个QUERY需要多次处理不同的表,否则我就要专为这个拖个QUERY了)
 
你用UNION试一试
 
先用循环语句判断哪个为空,然后再查询。
 
select case when a01='xxx' then
case when a011 is not null then a011
when a012 is not null then a012
when a013 is not null then a013
when a014 is not null then a014
else
null
end
else
a01
end
from tablename
 
多人接受答案了。
 
后退
顶部