创建 SQL 服务器 table 错误
Create SQL Server table error
我正在尝试使用查询结果创建一个新的 table。我在 SQL Server 2012
工作
CREATE TABLE [Service Contract Data].[dbo].[filtered_data] AS
(
SELECT *
FROM [Service Contract Data].[dbo].[New Data]
LEFT JOIN [Service Contract Data].[dbo].[OctMktSeg] ON [Service Contract Data].[dbo].[New Data].[Customer ID] = [Service Contract Data].[dbo].[OctMktSeg].[Account Number]
LEFT JOIN [Service Contract Data].[dbo].[tblMktSeg&MPI] ON [Service Contract Data].[dbo].[New Data].[Customer ID] = [Service Contract Data].[dbo].[tblMktSeg&MPI].[Customer ID1]
WHERE
(MKTSEG LIKE '%Repair%' OR MKTSEG LIKE 'Auto Glass' OR
MKTSEG LIKE 'IA - Individual' OR MKTSEG IS NULL)
AND (MPI LIKE 'N' OR MPI IS NULL)
AND [Item Category] LIKE '%Term'
AND [Month] >= '2015-01-01 00:00:00.000')
;
它一直告诉我第一个左括号附近有 "Incorrect syntax",我不知道为什么。想法?
我不知道该语法在 SQL 服务器中是否有效,您以前尝试过吗?
这是创建新 table:
的有效语法
SELECT
-- SPECIFY THE NAME OF THE COLUMNS IN THE SELECT LIST, AVOID *
*
--INSERT DATA INTO NEW TABLE
INTO [Service Contract Data].[dbo].[filtered_data]
from [Service Contract Data].[dbo].[New Data] t1
left join [Service Contract Data].[dbo].[OctMktSeg] t2 ON t1.[Customer ID] = t2.[Account Number]
left join [Service Contract Data].[dbo].[tblMktSeg&MPI] t3 on t1.[Customer ID] = t3.[Customer ID1]
WHERE (MKTSEG like '%Repair%' or MKTSEG like 'Auto Glass' or MKTSEG like 'IA - Individual' or MKTSEG is null)
and (MPI like 'N' or MPI is null)
and [Item Category] like '%Term'
and [Month] >= '2015-01-01 00:00:00.000'
您的 WHERE
之后似乎缺少一个开放的 peren (
WHERE ((MKTSEG like '%Repair%' or MKTSEG like 'Auto Glass' or MKTSEG like 'IA - Individual' or MKTSEG is null)
and (MPI like 'N' or MPI is null)
and [Item Category] like '%Term'
and [Month] >= '2015-01-01 00:00:00.000')
我正在尝试使用查询结果创建一个新的 table。我在 SQL Server 2012
工作CREATE TABLE [Service Contract Data].[dbo].[filtered_data] AS
(
SELECT *
FROM [Service Contract Data].[dbo].[New Data]
LEFT JOIN [Service Contract Data].[dbo].[OctMktSeg] ON [Service Contract Data].[dbo].[New Data].[Customer ID] = [Service Contract Data].[dbo].[OctMktSeg].[Account Number]
LEFT JOIN [Service Contract Data].[dbo].[tblMktSeg&MPI] ON [Service Contract Data].[dbo].[New Data].[Customer ID] = [Service Contract Data].[dbo].[tblMktSeg&MPI].[Customer ID1]
WHERE
(MKTSEG LIKE '%Repair%' OR MKTSEG LIKE 'Auto Glass' OR
MKTSEG LIKE 'IA - Individual' OR MKTSEG IS NULL)
AND (MPI LIKE 'N' OR MPI IS NULL)
AND [Item Category] LIKE '%Term'
AND [Month] >= '2015-01-01 00:00:00.000')
;
它一直告诉我第一个左括号附近有 "Incorrect syntax",我不知道为什么。想法?
我不知道该语法在 SQL 服务器中是否有效,您以前尝试过吗? 这是创建新 table:
的有效语法SELECT
-- SPECIFY THE NAME OF THE COLUMNS IN THE SELECT LIST, AVOID *
*
--INSERT DATA INTO NEW TABLE
INTO [Service Contract Data].[dbo].[filtered_data]
from [Service Contract Data].[dbo].[New Data] t1
left join [Service Contract Data].[dbo].[OctMktSeg] t2 ON t1.[Customer ID] = t2.[Account Number]
left join [Service Contract Data].[dbo].[tblMktSeg&MPI] t3 on t1.[Customer ID] = t3.[Customer ID1]
WHERE (MKTSEG like '%Repair%' or MKTSEG like 'Auto Glass' or MKTSEG like 'IA - Individual' or MKTSEG is null)
and (MPI like 'N' or MPI is null)
and [Item Category] like '%Term'
and [Month] >= '2015-01-01 00:00:00.000'
您的 WHERE
(
WHERE ((MKTSEG like '%Repair%' or MKTSEG like 'Auto Glass' or MKTSEG like 'IA - Individual' or MKTSEG is null)
and (MPI like 'N' or MPI is null)
and [Item Category] like '%Term'
and [Month] >= '2015-01-01 00:00:00.000')