'-' 附近的语法不正确。(Microsoft SQL Server Native Client 10.0)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26306509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:47:37  来源:igfitidea点击:

Incorrect Syntax near '-' .(Microsoft SQL Server Native Client 10.0)

sqlsql-serverssissyntax-error

提问by Sathiya

While doing SSIS job I got an error in my create table query

在做 SSIS 工作时,我的创建表查询出错

Incorrect Syntax near '-' .(Microsoft SQL Server Native Client 10.0)

'-' 附近的语法不正确。(Microsoft SQL Server Native Client 10.0)

SQL statement:

SQL语句:

CREATE TABLE Staging_ACD_Precision_Queue 
(
    PrecisionQueueID int,
    BucketIntervalID int,
    EnterpriseName varchar(32),
    AgentOrdering int,
    CallOrdering int,
    Description varchar(255),
    ServiceLevelThreshold int,
    ServiceLevelType smallint,
    ForceExpandingQueue varchar(1),
    Deleted varchar(1),
    ChangeStamp int,
    Partner varchar(4),
    Center varchar(4),
    Partner-Center varchar(9),
    LOB varchar(4),
    Circle varchar(4),
    TypeOfBusiness varchar(4)
)

I tried the above query. I guess from the error message that, the issue is in Partner-Center varchar(9)but I failed to fix this error. Since I'm new to SSIS and SQL queries I don't know to fix the issue.

我试过上面的查询。我猜从错误消息中可以看出,问题出在Partner-Center varchar(9)但我未能修复此错误。因为我是 SSIS 和 SQL 查询的新手,所以我不知道如何解决这个问题。

enter image description here

在此处输入图片说明

回答by Donal

You need to put square brackets around Partner-Center, e.g. [Partner-Center]. Embedded spaces or special characters are not allowed in field names, but you can escape them by putting the field name within square brackets.

您需要在 周围放置方括号Partner-Center,例如[Partner-Center]。字段名称中不允许嵌入空格或特殊字符,但您可以通过将字段名称放在方括号内来对它们进行转义。

CREATE TABLE Staging_ACD_Precision_Queue (
    PrecisionQueueID int,
    BucketIntervalID int,
    EnterpriseName varchar(32),
    AgentOrdering int,
    CallOrdering int,
    Description varchar(255),
    ServiceLevelThreshold int,
    ServiceLevelType smallint,
    ForceExpandingQueue varchar(1),
    Deleted varchar(1),
    ChangeStamp int,
    Partner varchar(4),
    Center varchar(4),
    [Partner-Center] varchar(9),
    LOB varchar(4),
    Circle varchar(4),
    TypeOfBusiness varchar(4)
)

As others have stated here, I too would like to recommend you avoid using a hyphen in the field name and go with either Partner_Centeror PartnerCenteras the field name instead of Partner-Center.

正如其他人在此处所述,我也建议您避免在字段名称中使用连字符,并使用Partner_CenterPartnerCenter作为字段名称而不是Partner-Center.

回答by Mureinik

SQL Server does not allow -in bare field names. However, you can "escape" it by surrounding the field name with square brackets ([]):

SQL Server 不允许-使用裸字段名称。但是,您可以通过用方括号 ( [])将字段名称括起来来“转义”它:

CREATE TABLE Staging_ACD_Precision_Queue (
    PrecisionQueueID int,
    BucketIntervalID int,
    EnterpriseName varchar(32),
    AgentOrdering int,
    CallOrdering int,
    Description varchar(255),
    ServiceLevelThreshold int,
    ServiceLevelType smallint,
    ForceExpandingQueue varchar(1),
    Deleted varchar(1),
    ChangeStamp int,
    Partner varchar(4),
    Center varchar(4),
    [Partner-Center] varchar(9),
    LOB varchar(4),
    Circle varchar(4),
    TypeOfBusiness varchar(4)
)

回答by Jeff Muzzy

You can't have "-" in column names. you can do underscores. but not minus signs.

列名中不能有“-”。你可以做下划线。但不是减号。

Actually you can however you have to [ ] around column name to create with a dash and everytime you want to access you have to [var]

实际上你可以但是你必须在列名周围 [] 用破折号创建,每次你想访问你都必须 [var]

Change

改变

Partner-Center varchar(9),

to be

成为

Partner_Center varchar(9),

or

或者

[Partner-Center] varchar(9)