用一个DBGrid控件显示数据,关联DataSource,先有两张表:
Table1
ID1 ID2 ...... 字段n
1 2Table2
Name id
北京 1
上海 2Table1中的ID1,ID2都是对应Table2中的id, DBGRID显示Table1的所有字段,但是ID1要显示'北京',ID2要显示'上海',而不是1跟2.请问各位大侠如何实现?
Table1
ID1 ID2 ...... 字段n
1 2Table2
Name id
北京 1
上海 2Table1中的ID1,ID2都是对应Table2中的id, DBGRID显示Table1的所有字段,但是ID1要显示'北京',ID2要显示'上海',而不是1跟2.请问各位大侠如何实现?
2.用条件,比如sql server中的Case,去组合sql语句
select
case id when 1 then '北京'
when 2 then '上海'
end
from table
(select name from table2 where id=a.id1) as id1,
(select name from table2 where id=a.id2) as id2,
(select name from table2 where id=a.id3) as id3,
...
from table1 a