Incorrect syntax near "-". (Microsoft SQL Server Native Client 10.0)
While doing SSIS job, I got an error in my create table query
Incorrect syntax near '-'. (Microsoft SQL Server Native Client 10.0)
SQL statement:
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 think from the error message that the problem is in Partner-Center varchar(9)
, but I was unable to fix this error. Since I'm new to SSIS and SQL queries, I don't know how to fix this issue.
source to share
You need to put square brackets around Partner-Center
for example. [Partner-Center]
... Nested spaces or special characters are not allowed in field names, but you can avoid them by placing the field name in square brackets.
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 I said here, I also recommend that you do not use a hyphen in the field name and go with Partner_Center
or PartnerCenter
as the field name instead Partner-Center
.
source to share
SQL Server does not allow -
you to specify field names. However, you can "escape" it by surrounding the field name with square brackets ( []
):
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)
)
source to share
You cannot have "-" in column names. you can make an underline. but not minus signs.
Actually you can [] use the column name to create with a dash and every time you want to access you have to [var]
Change
Partner-Center varchar(9),
to be
Partner_Center varchar(9),
or
[Partner-Center] varchar(9)
source to share