|
■No81738 (Artor さん) に返信
スマートか分かりませんがこんなのはどうでしょう?
Dim tbl As New DataTable()
With tbl.Columns
.Add("CD", GetType(String))
.Add("DT", GetType(String))
.Add("TB", GetType(String))
End With
tbl.Rows.Add("001", "鈴木", "A.name")
tbl.Rows.Add("001", "田中", "A.name")
tbl.Rows.Add("002", "東京", "A.front")
tbl.Rows.Add("003", "経理", "A.buka")
tbl.Rows.Add("003", "人事", "A.buka")
Dim whr As New System.Text.StringBuilder
For Each itm In (From r In tbl.AsEnumerable
Select CD = r.Field(Of String)("CD"), DT = r.Field(Of String)("DT"), TB = r.Field(Of String)("TB")
Let Value = String.Format("{0}='{1}'", TB, DT)
Group Value By CD Into Values = Group)
If whr.Length > 0 Then whr.AppendLine(" AND ")
If itm.Values.Count > 1 Then whr.Append("(")
whr.Append(String.Join(" OR ", itm.Values.ToArray))
If itm.Values.Count > 1 Then whr.Append(")")
whr.AppendLine()
Next
Console.WriteLine(whr.ToString)
|