Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...