String Manipulation

  • HI All,

    I am using Exec to execute a string which will restore a database.

    /****************************************************************************/

    /* Drop the database.                                                       */

    /****************************************************************************/

    use master

    go

    if exists (select * from master.dbo.sysdatabases where name = 'hello')

     begin

     drop database [hello]

     end

     /****************************************************************************/

     /* Restore the database hello                                                  */

     /****************************************************************************/

            exec ('restore database [hello]

            from disk= 'c:\yukon_files\adworksbackup'

            with

            move 'AdventureWorks_Data' to 'c:\\hello.mdf', 

            move 'AdventureWorks_Log'  to  'c:\\hello.ldf'')

             go

      

            The drop database command is working fine. But the restore is failing dues to the single quotes after the .ldf file.

    I am actually using Perl to interact with html file to restore the database. The enteries like the database name, backup disk location, and the new position of the files is entered in a .html page and then the Perl application connects to the sql database and executes the sql scripts.

    Any ideas how to manipulate the restore statement so as to get it work.

    --Kishore

     

     

  • Hi Kishore, you need to double up on the single quotes when you're doing this sort of thing, rewrite what you're doing as follows.

    exec ('restore database [hello]

            from disk= ''c:\yukon_files\adworksbackup''

            with

            move ''AdventureWorks_Data'' to ''c:\\hello.mdf'',

            move ''AdventureWorks_Log''  to  ''c:\\hello.ldf''')

    Hopefully this should fix your problem, if not feel free to let us know .

    Mike

  • What about QUOTENAME()?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • hmmmm.... something else that i didn't know existed

    Cheers Frank

  • Hi Mike,

    I used double single quotes as you mentioned and it worked fine.

    Thanks.

    --Kishore

     

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

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