Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Some Undocumented Stored Procedures


Some Undocumented Stored Procedures

Author
Message
achigrik
achigrik
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 1
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/achigrik/someundocumentedstoredprocedures.asp



Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55862 Visits: 40408
Heh... judging from the number of forums you have this same article posted on, I'd say you have some work cut out for you in making a correction. ;-)

xp_DirTree actually takes 3 operands:
1. The path to a folder. This may be a UNC or drive path.
2. The number of levels below the path in the first operand. If missing, the default is "0" which equates to "all levels" which, as you know, can be terribly long. Levels above "0" operate as expected where Level 1 is the current directory only.
3. There's a third operand that most are simply not aware of. The default for this operand is "0" which means "only list directories". If this operand is set to any non-zero value, the output will return a 3rd column named "File". It should have been called "IsFile" because a "1" in this column means the "Subdirectory" column actually contains a file name instead of a folder name.

So, try running this and see what you get...
EXEC Master.dbo.xp_DirTree 'C:\',1,1

Think of it as an xp_FileExists on steroids. You can also capture the output for processing using something like the following:

CREATE TABLE #MyDir
(
RowNum INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,
FolderFileName VARCHAR(128),
Depth TINYINT,
IsFile TINYINT
)

INSERT INTO #MyDir
(FolderFileName, Depth, IsFile)
EXEC Master.dbo.xp_DirTree 'C:\',1,1

SELECT * FROM #MyDir


Of course, the first operand may be contained in a variable without any dynamic SQL being necessary.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search