|
本帖最后由 鱼儿游游 于 2012-7-18 23:33 编辑
我现在的方法是用了临时表(LSB、LSB1):调用下面的过程(GetAllSub),生成的数据表LSB就是我要的结果。
我想实现:不用临时表,只用SQL语句也能得到同样结果的记录集。- Sub test()
- GetAllSub 2
- End Sub
- Public Sub GetAllSub(ByVal intParentID As Integer)
- Dim strSQL As String
- Dim blnSaerch As Boolean
- strSQL = "SELECT CategoryID,CategoryLabel INTO LSB FROM GoodsCategory WHERE ParentID=" + CStr(intParentID)
- DoCmd.SetWarnings False
- DoCmd.RunSQL strSQL
-
- blnSaerch = True
- While blnSaerch
- strSQL = "SELECT CategoryID,CategoryLabel INTO LSB1 FROM GoodsCategory WHERE ParentID IN (SELECT CategoryID FROM LSB) AND CategoryID NOT IN (SELECT CategoryID FROM LSB)"
- DoCmd.RunSQL strSQL
- If DCount("CategoryID", "LSB1") > 0 Then
- strSQL = "INSERT INTO LSB (CategoryID,CategoryLabel) SELECT CategoryID,CategoryLabel FROM LSB1"
- DoCmd.RunSQL strSQL
- Else
- blnSaerch = False
- End If
- Wend
- End Sub
复制代码 |
|