How to do a select from sp_helpdb''s output ?

  • Hi friends,

    I want to select only filename column of sp_helpdb's output.But I don't know how should I do this? Other way is doing a direct select from sysfiles or sysdatabases but as you know microsoft doesn't recommand this way. Also I can select that filed in my application level but it is strange for me: Of course sql server should has a proper way to do a select from output curosr of this procedure,Doesn't it?

    -Thanks in advance

  • Can't find a way of doing this without using sysfiles - here's an example, if you need it:

    declare @dbname varchar(100)

    declare @strSQL nvarchar(500)

    set @dbname = 'master'

    set @strSQL = 'select name, fileid, filename from ' + @dbname + '.dbo.sysfiles'

    exec sp_executesql @strSQL

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Lets think in reverse form! I have a procedure that returns a heavy cursor(not just like st_helpdb).Sould I transfer such a set to client (This can be application server or really a client application)? I think this is so bad way! So I infer microsoft guys should have innovated another way! Maybe I am so optimistic! Clarify me.

    -Thanks

  • What is it you need to do exactly??

  • The simplest solution to this problem, and not neccessarily the most elegant is to copy the stored procedure sp_helpdb into a new stored procedure called something like sp_helpdbname. Once you have changed the name of the stored procdure at the top, you can then move to the bottom of the code and rem out from the select statement what you don't want returned.

    This also allows you to see how they built the procedure and if you want remove any uneccessary code from your new stored procedure.

  • Try this, creates a temporary table (#tmp), populates it with the output from 'sp_helpdb' using EXEC.  You can then select from the  temp table as normal :

    create table #tmp (name varchar(200),

    varchar(20),

    owner varchar(50),

    dbid int,

    created datetime,

    status varchar(4000),

    compat int)

    go

    insert #tmp exec sp_helpdb

    select * from #tmp where name like 'm%' -- Get all databases beginning with 'm'

    HTH

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply