以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何根据条件替换重复数据  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=87703)

--  作者:xujie80
--  发布时间:2016/7/17 17:46:00
--  如何根据条件替换重复数据

户号是一户家庭成员的标志,如何只保留户主关系中年龄最大的一位为户主,而删除同户号中其他成员的户主关系为空白?

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:户主.table


--  作者:y2287958
--  发布时间:2016/7/17 23:20:00
--  
Dim cmd As New SQLCommand
cmd.CommandText = "s elect [_Identify] from"
cmd.CommandText += "(s elect 户号, max(年龄) As 年龄 from {表A} group by 户号) as a"
cmd.CommandText += " inner join {表A} as b on a.户号 = b.户号 And a.年龄 = b.年龄"
Dim dt As DataTable = cmd.ExecuteReader()
DataTables("表A").DeleteFor("_Identify not in (" & dt.GetComboListString("_Identify").Replace("|",",") & ")")

--  作者:xujie80
--  发布时间:2016/7/18 9:10:00
--  
谢谢,非常妙。我只想把这些行“户主”替换成空白,并不想删除行,该如何写?原谅我是一小白,请不吝赐教。
--  作者:xujie80
--  发布时间:2016/7/18 9:28:00
--  
DataTables("表A").ReplaceFor("户主关系","","_Identify not in (" & dt.GetComboListString("_Identify").Replace("|",",") & ")")
--  作者:大红袍
--  发布时间:2016/7/19 1:16:00
--  
DataTables("表A").ReplaceFor("户主关系", nothing,"_Identify not in (" & dt.GetComboListString("_Identify").Replace("|",",") & ")")