0

I am creating a new table into database. My code is below

CREATE TABLE Master_data AS
select a.*, COALESCE(b.content_view,0) as content_view, COALESCE(b.headline_view,0) as headline_view
FROM [Britannia_MMx_2021].[dbo].[Sales_20210323] a
left join [Britannia_MMx_2021].[dbo].[Doximity_20220328] b on a.NPI = b.NPI
           and a.Year_Mon = b.Date;

I am getting this error

Msg 102, Level 15, State 1, Line 46
Incorrect syntax near '('.
2
  • 3
    Are you sure this is MySQL? Commented Mar 29, 2022 at 2:45
  • how come you error is on line 46, provided SQL has 5 lines Commented Mar 29, 2022 at 2:47

1 Answer 1

1

Your SQL snippet displays characteristics of TSQL. In TSQL (e.g. in MS SQL Server) you do not use "create table as" followed by a select statement, instead you use an INTO clause e.g.

SELECT a.*
    , COALESCE(b.content_view, 0) AS content_view
    , COALESCE(b.headline_view, 0) AS headline_view
INTO Master_data
FROM [Britannia_MMx_2021].[dbo].[Sales_20210323] a
LEFT JOIN [Britannia_MMx_2021].[dbo].[Doximity_20220328] b ON a.NPI = b.NPI
    AND a.Year_Mon = b.DATE;

In MySQL you do use CREATE TABLE [ IF NOT EXISTS ] new_table [ AS ]

Sign up to request clarification or add additional context in comments.

Comments

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.