sql server scheduled job fails if double quote around db name

  • Hi, i have a database having dash in the db name - MMG-Events, do I have to add double quote around the db name in command, but the following command fails in sql server scheduled job:

    USE "MMG-Events";

    Date3/30/2012 11:53:10 AM

    LogJob History (test)

    Step ID1

    Serverxxx

    Job Nametest

    Step Namestep1

    Duration00:00:00

    Sql Severity15

    Sql Message ID102

    Operator Emailed

    Operator Net sent

    Operator Paged

    Retries Attempted0

    Message

    Executed as user: abc. Incorrect syntax near 'MMG-Events'. [SQLSTATE 42000] (Error 102). The step failed.

  • USE [MMG-Events];

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • SET QUOTED_IDENTIFIER OFF

    USE "SandBox";

    select * from sys.tables

    --above shows a syntax error

    GO

    SET QUOTED_IDENTIFIER ON

    USE "SandBox";

    select * from sys.tables

    --above works just fine

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Using [MMG-Events] makes for better code portability than relying on quoted identifiers being on.


    For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden[/url] for the best way to ask your question.

    For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw[/url]

    Need to Split some strings? Jeff Moden's DelimitedSplit8K[/url]
    Jeff Moden's Cross tab and Pivots Part 1[/url]
    Jeff Moden's Cross tab and Pivots Part 2[/url]

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

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