What is the shortest way to do this? I can create a temporary table and then join the result, but is there a practical way to do it in one step? My procedure is complex, with multiple parameters and need to be executed each time.
CREATE PROCEDURE [dbo].[Get_Directory]
@Path VARCHAR(100) = 'c:\windows\temp\'
AS
BEGIN
SET NOCOUNT ON;
DECLARE @rc INT;
DECLARE @p VARCHAR(100) = 'dir /b '+ @path
EXEC @rc = master..xp_cmdshell @p;
END
SELECT *
FROM table T
LEFT JOIN (get_directory @path='c:\windows\temp\*') D ON D.output LIKE '%' + T.blabla + '%'