I need to write a stored procedure that will take in a string to search a tree like structure and perform a recursive result set. First, here is the table:
CREATE TABLE [dbo].[WorkAreas] (
[Id] uniqueidentifier DEFAULT newid() NOT NULL,
[Name] nvarchar(max) COLLATE Latin1_General_CI_AS NULL,
[ParentWorkAreaId] uniqueidentifier NULL,
CONSTRAINT [PK__WorkArea__3214EC073FD07829] PRIMARY KEY CLUSTERED ([Id]),
CONSTRAINT [WorkArea_ParentWorkArea] FOREIGN KEY ([ParentWorkAreaId])
REFERENCES [dbo].[WorkAreas] ([Id])
ON UPDATE NO ACTION
ON DELETE NO ACTION,
)
I'd Like the stored procedure to output the results like this:
Work Area 1 - Child Of Work Area 1 - Child Child Of Work Area 1
So if this were real data it may look like this:
Top Floor - Room 7 - Left Wall
Top Floor - Room 9 - Ceiling
the stored procedure would take in a parameter: @SearchTerm varchar(255)
The search term would look at the results and perform a "contains" query.
So if we passed in "Room 9" the result should come up with the Room 9 example, or if just the word "Room" was passed in, we would see both results.
I am not sure how to construct the SP to recursively build the results.