sql server scheduled job fails if double quote around db name

  • zxmgh

    SSC Eights!

    Points: 911

    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";

    Date 3/30/2012 11:53:10 AM

    Log Job History (test)

    Step ID 1

    Server xxx

    Job Name test

    Step Name step1

    Duration 00:00:00

    Sql Severity 15

    Sql Message ID 102

    Operator Emailed

    Operator Net sent

    Operator Paged

    Retries Attempted 0

    Message

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

  • Gail Shaw

    SSC Guru

    Points: 1004446

    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
  • Lowell

    SSC Guru

    Points: 323398

    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!

  • CapnHector

    SSCoach

    Points: 16083

    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 4 (of 4 total)

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