How to skip space in a query

Paria k 21 Reputation points
2021-02-26T20:23:45.757+00:00

Hello,

I am trying to alter credentials using a SQL query "ALTER CREDENTIAL credential_name WITH IDENTITY = 'identity_name'
[ , SECRET = 'secret' ]"

And the issue is that my credential_name has a space in it. so that would make my query look something like:

ALTER CREDENTIAL HCC SQL WITH IDENTITY = 'username', SECRET = 'password';

Which gives me the following error:

Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'SQL'.
Msg 319, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

So I was wondering if there is a way to skip the space in this query?
Or would I have to change my credential_name to something with no spaces?

Thanks

SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Tom Phillips 17,771 Reputation points
    2021-02-26T21:09:41.99+00:00

    ALTER CREDENTIAL [HCC SQL] WITH

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2021-02-26T20:41:41.8+00:00

    Did you already try ALTER CREDENTIAL [HCC SQL] WITH...?

    1 person found this answer helpful.
    0 comments No comments

  2. Cris Zhan-MSFT 6,661 Reputation points
    2021-03-01T06:08:53.427+00:00

    Hi,

    The square brackets [ ] and double quotation marks (") are used to delimit identifiers. This is necessary if the object name(identifier) is a reserved keyword or contains special characters such as a space or hyphen.
    https://stackoverflow.com/questions/9917196/meaning-of-square-brackets-in-ms-sql-table-designer

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.