MsSQL: 方案一: select fieldname from( select 'field1' fieldname,count(field1) as num from yourtable union select 'field2',count(field2) from yourtable union ... union select 'field100',count(field100) from yourtable ) as vTable where num>0
select count(feild1) as feild1,count(feild2) as feild2,.......count(feild100) as feild100 from tablefeild1 30 feild2 30 feild3 29 feild4 28 .... ... ==> 'select ' + 'feild1 ,'+'feild2,'+feild............... from table
具体点,一百个字段?还是一百条记录?
方案一:
select fieldname
from(
select 'field1' fieldname,count(field1) as num from yourtable
union
select 'field2',count(field2) from yourtable
union
...
union
select 'field100',count(field100) from yourtable
) as vTable
where num>0
feild2 30
feild3 29
feild4 28
....
...
==>
'select ' + 'feild1 ,'+'feild2,'+feild............... from table
原因数据插入的时候只对其中的几个字段进行插入,大部分的字段没有进行插入,
现在就要取出这些已经有数据插入的字段名.(主要是用来判断,上一次的SQL操作是对哪些字段进行了操作)
谢谢各位大虾啊!!
然后用mysql_fetch_field就可以了