How to query folder and document both so that we can get:
- All the subfolder documents.
- Only the folder documents.
- Count of documents in the subfolder, with the folder name.
How to query folder and document both so that we can get:
All documents within a folder and all its subfolders:
SELECT *
FROM dm_document
WHERE FOLDER('/MyCabinet/MyFolder', DESCEND)
All documents within a folder without subfolders:
SELECT *
FROM dm_document
WHERE FOLDER('/MyCabinet/MyFolder')
I took the liberty to name queries a bit differently than OP asked it, but it fits it too. It is just a bit more clearer what some query returns. I used Temp folder for this example.
SELECT * FROM dm_document WHERE FOLDER('/Temp', DESCEND)
SELECT * FROM dm_document WHERE FOLDER('/Temp')
SELECT COUNT(doc.r_object_id) AS doc_ammount, fol.object_name AS folder_object_name FROM dm_document doc, dm_folder fol WHERE FOLDER('/Temp', descend) AND ANY doc.i_folder_id = fol.r_object_id GROUP BY (fol.object_name)
All the subfolder documents:
SELECT r_object_id, object_name
FROM dm_document(all)
WHERE folder('/myCabinet/myFolder/', DESCEND)
Only the folder documents: I guess it's similar to the query above but without the DESCEND
keyword. (I can't test it now.) (I'm also not sure that (all)
is required or not.)
In case you have unique folder in docbase and you want to find documents in this folder
select * from dm_document where any i_folder_id in (select r_object_id from
dm_folder where object_name='unique_folder_name')