Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

sql - Msg 156, Level 15, State 1, Procedure OneColumnIntoView2, Line 4 [Batch Start Line 2] Incorrect syntax near the keyword 'FROM'

I have an error in my code when I execute, it gives me an error, I don't know what should I change.

My code is:

ALTER PROCEDURE [dbo].[SP_OneColumnIntoView]
AS
BEGIN
    EXEC('CREATE VIEW OneColumnIntoView2
          AS    
              SELECT *
              FROM OPENJSON ((SELECT QUOTENAME(STRING_AGG(VALUE, ''), '') AS JC 
                              FROM OneColumnJsonFood))

              ;WITH (FID INT, Fname NVARCHAR(50), Ftype NVARCHAR(20),
                     Fcount INT, Datetype NVARCHAR(4000), Fregion NVARCHAR(50),
                     Fdescription NVARCHAR(100)) AS WithJson
')

END

Error:

Msg 156, Level 15, State 1, Procedure OneColumnIntoView2, Line 4 [Batch Start Line 2]
Incorrect syntax near the keyword 'FROM'

PS: If I put ; it gave me this error:

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...