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
563 views
in Technique[技术] by (71.8m points)

sql - 使用GO,“ CREATE VIEW”必须是查询批处理中的第一个语句”错误('CREATE VIEW' must be the first statement in a query batch' error using GO)

I have the following query:

(我有以下查询:)

CREATE VIEW VIEW#1 AS
SELECT * FROM rota

go
--view#02 – apresentar os voos programados para cada rota.

CREATE VIEW VIEW#2 AS
SELECT TOP (select COUNT(*) FROM voo) IDrota, IDvoo
FROM voo
ORDER BY IDrota

GO
--view#03 – apresentar os técnicos de apoio para cada um dos voos programados.

CREATE VIEW VIEW#3 AS
SELECT TOP (select COUNT(*) FROM tecnicosVoo) V.IDvoo, TV.IDfuncionario, F.PrimeirosNomes, F.UltimosNomes, F.fun??oTecnico FROM voo V
    JOIN tecnicosVoo TV ON V.IDvoo = TV.IDvoo
    JOIN funcionario F ON TV.IDfuncionario = F.IDfuncionario
    ORDER BY IDvoo

GO
--view#04 – apresentar os voos programados para cada rota e os respetivos avi?es associados.

CREATE VIEW VIEW#4 AS
SELECT TOP (SELECT COUNT(*) FROM voo) R.IDrota, V.IDvoo, A.refAviao, A.modelo AS 'Modelo do avi?o' FROM voo V
    JOIN rota R ON V.IDrota = R.IDrota
    JOIN aviao A ON V.refAviao = A.refAviao
    ORDER BY R.IDrota

--view#05 - apresentar para um voo a rela??o de lugares disponiveis

go

CREATE VIEW VIEW#5 AS
SELECT TOP (SELECT COUNT(*) FROM voo) VO.IDvoo, A.NT_passageiros 'Capacidade do avi?o', (SELECT count(*) FROM VendaVoo where IDvoo = VO.IDvoo and ocupacao = 1) 'Ocupados',
(select round((100.0 - ((select CAST((SELECT count(*) FROM VendaVoo where IDvoo = VO.IDvoo and ocupacao = 1) AS FLOAT) / CAST(A.NT_passageiros AS FLOAT)) * 100)), 2)) 'Percentagem de lugares disponiveis'
FROM voo VO
    JOIN aviao A ON VO.refAviao = A.refAviao

And it is giving me this error: "Msg 102, Level 15, State 1, Procedure VIEW#4, Line 640 Incorrect syntax near 'GO'. Msg 111, Level 15, State 1, Procedure VIEW#4, Line 640 'CREATE VIEW' must be the first statement in a query batch."

(它给了我这个错误:“消息102,级别15,状态1,过程VIEW#4,行640'GO'附近的语法不正确。消息111,级别15,状态1,过程VIEW#4,行640'创建“ VIEW”必须是查询批处理中的第一条语句。”)

So the query creates the view 1, 2 and 3 but doesnt create the other one's.

(因此,查询将创建视图1、2和3,但不会创建其他视图。)

Someone know why?

(有人知道为什么吗?)

  ask by miguel__frtt translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

...