use clause

  • Hi Experts,
    Is there any possibility to execute this query in sql 2008 sp3 without errors and without using dynamic t-sql query

    IF(1=2)
    begin
        use [not_existing_database];
    end

    ----------------------------------------------
    Msg 911, Level 16, State 1, Line 3
    Database 'not_existing_database' does not exist. Make sure that the name is entered correctly.

    Cheers,
    Marcin

  • That error is returned by the parser, so no.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • It may depend on specifically what you're trying to do.

    For example, if you just want to execute a stored proc in the context of that db, you can do this:

    IF {some condition}
        EXEC db_that_may_not_exist.dbo.stored_proc_name

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

Viewing 3 posts - 1 through 2 (of 2 total)

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