0

Hello I am trying to solve this problem

Given a database table such as: create table file(id int, parentid int, name varchar(1024), size int, type char(1)); write a single (recursive) database query to list FULL PATH of all files. [assume type is either "F" or "D" for file or directory]. Your query should give you similar output to unix command: "find . -type f".

This is what I've got so far but I dont know if its right

 Create FUNCTION GetFileName
    (
     @fullpath nvarchar(260)
    ) 
    RETURNS nvarchar(260)
    AS
    BEGIN
    DECLARE @charIndexResult int
    SET @charIndexResult = CHARINDEX('\', REVERSE(@fullpath))

    IF @charIndexResult = 0
        RETURN NULL 

I have tried doing that but I dont really know what i'm doing as I am stuck after that code

1 Answer 1

1

You'll need to use non-standard SQL to create a recursive query, look into Common Table Expressions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.