在树形结构中,我想在父记录中查找一个值,以查看它在名为nodOpen的字段中是否具有值(对于封闭可以为0,对于开放可以为1)。如果父记录字段nodOpen为1,则当前记录可见,反之亦然。
strSQL = "SELECT nodLevel, nodNum, nodLead, etc., nodParent FROM tblNode WHERE PARENTNODE IS OPEN Visible= 1 ORDER BY nodSort"
用一个SQL语句可能吗?
假定表具有以下结构。
create table tblNode (
nodNum int not null,
nodLevel int,
nodOpen int not null,
nodSort int not null,
nodLead int not null,
nodParent int null,
-- insert other columns here(?)
constraint PK_tblNode primary key clustered (nodNum),
constraint FK_tblNode_tree foreign key (nodParent)
references tblNode(nodNum)
);
查询看起来像这样。
select
nodLevel,
nodNum,
nodLead,
nodParent,
nodSort -- you may have to include this column to sort on it later
/* insert other columns here(?) */
from tblNode as childNode
inner join tblNode as parentNode on parentNode.nodNum = childNode.nodParent
where parentNode.nodOpen = 1
order by nodSort