'sp_MSforeachdb' expects parameter '@command1',

  • Hi,

    I get the error msg

    "Procedure or function 'sp_MSforeachdb' expects parameter '@command1', which was not supplied."

    when i run the following: What am i doing wrong?

    EXEC sp_MSForeachdb 'USE [?]

    IF DB_ID(''?'') > 4

    BEGIN

    select table_name from [?].information_schema.tables

    where table_name = "table1"

    END

    '

    thanks

  • Try it this way

    SP_MSForEachDb 'SELECT table_name from [?].information_schema.tables

    where table_name = "table1"'

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • it is working for me. I have tested it both on SQL 2005 SP3 and SQL 2008 R2. What version are you running it on?

  • pankushmehta (2/3/2011)


    it is working for me. I have tested it both on SQL 2005 SP3 and SQL 2008 R2. What version are you running it on?

    SQL 2005 SP3 and SQL 2008

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Very well might be collation. Look in the master database for the sp_MSforeachdb reference under programming. If you have a server with non-standard collation and the sp call is not exactly as the master database has it, it will say it does not exist when it does. Hope that helps.

    Rondall

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

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