SELECT DISTINCT * FROM DEP WHERE dep_code in (SELECT DISTINCT dep_up FROM DEP WHERE dep_code in ( SELECT DISTINCT dep_up FROM DEP WHERE dep_code in (SELECT dep_code FROM PERSON_LIMITS WHERE UPPER(account)='" + UserAccount + "'))) order by dep_code
我改成LINQ方式:
var result = from d in ((Entities)this.DataContext).DEP
let p = ((Entities)this.DataContext).PERSON_LIMITS.Where(x => x.ACCOUNT.ToUpper() == useraccount).Select(n => n.DEP_CODE)
where p.Contains(d.DEP_CODE)
orderby d.DEP_CODE.Distinct()
select d;