0

I'm trying to create a new table with the results from a query. I'm working in 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')
    ;

It keeps telling me there's "Incorrect syntax" near the first open parentheses and I have no idea why. Thoughts?

2
  • Are there columns in the joined table that overlap in the query? Commented Jan 13, 2016 at 22:36
  • Does the select statement execute correctly on its own? Commented Jan 13, 2016 at 22:39

2 Answers 2

1

I don't know if that syntax is valid in SQL SERVER, Have you tried this before ? This is valid syntax in order to create a new 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'
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you're missing an open peren ( right after your 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')

1 Comment

The query executes correctly on it's own so I don't think it's an issue with the select query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.