Using a Hidden Stored Procedure

1k Views Asked by At

I am trying to use the following stored procedure to obtain databases from a server. However, I just want the databases created from a month ago. What do I have to do to make this work?

Here is the code:

sp_msforeachdb 'IF ''?'' like ''z%'' 
BEGIN
  print ''?''
END'

I just want the databases that begin with Z that were created during a certain month.

1

There are 1 best solutions below

4
On BEST ANSWER

How about this instead.

select name
    from sys.databases
    where name like 'z%'
        and create_date >= dateadd(mm,-1,getdate())