可以用循环,循环体为: select distinct &a from 表1 if &a=null fieldname[i]=field(i) endif 这样就可以提取出相应的字段名了
如果你的VFP可以得到该表的所有字段,则很简单的。 (在SQL SERVER 中,select name from syscolumns where id = object_id(n'[dbo].[tablename]') strfields = "" for i = 1 to n strsql = " select " & fieldname(i) & " from tablename where " & fieldname(i) & " <> '' " set rs = nothing set rs = cn.execute (strsql) if rs.rowcount = 0 then strfields = iif(len(strfields)>0,strfields & "," & fieldname(i),fieldname(i)) end ifnext strsql = "select " & strfields & " from tablename " set rs = cn.execute(strsql) 注:我写的是VB代码,在VFP中需要更该一下的,但原理一样。
如
select I from 表1 where 体育 is null
结果是
语文 数学 英语 政治 体育
86 85 20
78 76 59
而我只想的到如
体育 这一空列
是否只列出“为空”的字段,而不是select * ?
如果这样的话,看来你的数据库得要重新设计了,否则是很困难的。记录和字段的含义是不同的。如果是在SQL SERVER或Orcale,这个问题还是好解决,但是VFP就不行了。
基本思路是这样的:
1)循环,得到值全为空的字段名
2)将这些字段名组成一个SQL语句
3)执行这个SQL
select distinct &a from 表1
if &a=null
fieldname[i]=field(i)
endif
这样就可以提取出相应的字段名了
(在SQL SERVER 中,select name from syscolumns where id = object_id(n'[dbo].[tablename]')
strfields = ""
for i = 1 to n
strsql = " select " & fieldname(i) & " from tablename where " & fieldname(i) & " <> '' "
set rs = nothing
set rs = cn.execute (strsql) if rs.rowcount = 0 then
strfields = iif(len(strfields)>0,strfields & "," & fieldname(i),fieldname(i))
end ifnext
strsql = "select " & strfields & " from tablename "
set rs = cn.execute(strsql)
注:我写的是VB代码,在VFP中需要更该一下的,但原理一样。