CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    TSQL Error on the Following Statement

    Good Morning Guys

    I have the Following statement, that works well when i test it alone

    Code:
    declare @Results int exec [dbo].[sp_RestoreDatabase_O_Booking] 'MasekoTS','MasterDatabase', @Results OUT
    But now, i want to include this code in a Stored Procedure and i tried to do it like this

    Code:
    SELECT @sql1 = 'Declare @Results int exec [dbo].[sp_RestoreDatabase_O_Booking] ''' + @DB + ''', ''' + @Filename + '''@Results OUT'''
    execute ( @sql1 )

    and i get the Following Error

    Msg 105, Level 15, State 1, Line 1
    Unclosed quotation mark after the character string 'sp_RestoreDatabase_O_Bookin'.
    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'sp_RestoreDatabase_O_Bookin'.
    Thank you
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: TSQL Error on the Following Statement

    Hi.
    A good idea when you get such an error is to try and print out what you want to execute - that should help you find the unclosed quotation mark:

    so "print sql1" before executing it, and then copy the statement printed into the query window and it should be easy enough to see where the quotation mark problem is located:


    If you want your declare to look like the initial statement you wrote, I'd say you lack a comma before @Results OUT and you have 2 too many ' after @Results OUT.

    So like this:
    Code:
    SELECT @sql1 = 'Declare @Results int exec [dbo].[sp_RestoreDatabase_O_Booking] ''' + @DB + ''', ''' + @Filename + ''', @Results OUT'
    But try printing it out as mentioned, and it should be easy enough to find problems with quotation marks. Especially if you have set your IDE up to color strings for you.

    Hope this helps.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: TSQL Error on the Following Statement

    Also, plug it into SQL Mgmt and try to execute it. That used to be the trick doing Access/VB6. Access points to the SQL errors.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured