A blog about SQL Server, SSIS, C# and whatever else I happen to be dealing with in my professional life.

Find ramblings

Wednesday, August 27, 2008

Query to build SSIS qualified path

I had been hemming and hawing on how to best deal with the recursive nature of paths in SQL Server. This query is going to be what I need to build out the path correctly and being a good geek, I share.

TODO: add pictures so people have an idea of what it would look like


;
WITH FOLDER_STRUCTURE AS
(
SELECT
F.folderid
, cast('MSDB/' as nvarchar(max)) As folder_path
FROM
msdb.dbo.sysdtspackagefolders90 F
WHERE
folderid = '00000000-0000-0000-0000-000000000000'
UNION ALL
SELECT
F.folderid
, R.folder_path + F.foldername + '/' As folder_path
FROM
FOLDER_STRUCTURE R
INNER JOIN
msdb.dbo.sysdtspackagefolders90 F
ON F.parentfolderid = R.folderid
)
, PACKAGES AS
(
SELECT
P.name AS package_name
, P.folderid
, P.id as package_id
, P.createdate as package_createdate
, P.vermajor
, P.verminor
, P.verbuild
FROM
msdb.dbo.sysdtspackages90 P
)
SELECT
FS.folder_path + P.package_name
FROM
PACKAGES P
INNER JOIN
FOLDER_STRUCTURE FS
ON FS.folderid = p.folderid

No comments: