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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

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

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