none
SQL sintaks "USE DataBase" RRS feed

  • Question

  • When change the cursor in the SQL managment studio from the base 'TEST_0150' to base 'TEST_0150_Clon' for each base my first Variation works the other not. If anybody knows the answer why the variation 2 cursor is not moved to the desired base.

    Thanks in advance.

    1)
    USE TEST_0150_Clon

    2)
    DECLARE @ BaseClon NVARCHAR (4000) - Database Name for clone
    DECLARE @ SQLString NVARCHAR (4000) - the SQL string

    SET @ BaseClon = 'TEST_0150_Clonirana'
    SET @ SQLString = 'USE' + QuoteName (@ BaseClon)

    EXEC sp_executesql @ SQLString

    Monday, November 25, 2013 11:27 AM

Answers

All replies

  • When change the cursor in the SQL managment studio from the base 'TEST_0150' to base 'TEST_0150_Clon' for each base my first Variation works the other not. If anybody knows the answer why the variation 2 cursor is not moved to the desired base.

    Thanks in advance.

    1)
    USE TEST_0150_Clon

    2)
    DECLARE @BaseClon NVARCHAR (4000) - Database Name for clone
    DECLARE @SQLString NVARCHAR (4000) - the SQL string

    SET @BaseClon = 'TEST_0150_Clon'
    SET @SQLString = 'USE' + QuoteName (@BaseClon)

    EXEC sp_executesql @SQLString



    Monday, November 25, 2013 11:31 AM
  • EXEC sp_executesql @ SQLString


    Your dynamic SQL will be execute by sp_executesql  in a separate session, not in your current session.

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Monday, November 25, 2013 11:48 AM
  • Thanks a lot.

    Best regards.

    Monday, November 25, 2013 12:32 PM