INSERT INTO查询执行正常,但无法保存为视图

时间:2015-03-04 09:54:53

标签: sql sql-server

INSERT INTO dbo.[800_00_Index_SM_00_00_TMP]
SELECT dbo.[800_00_Index_SM_00_10].CertId, 
dbo.   [800_00_Index_SM_00_10].Certificato, 
dbo.[800_00_Index_SM_00_10].ALCertificato,  dbo.[800_00_Index_SM_00_10].DocNr, 
dbo.[800_00_Index_SM_00_10].ALDocNr, dbo.[800_00_Index_SM_00_10].Eti, 
dbo.[800_00_Index_SM_00_10].ALeti, 
dbo.[800_00_Index_SM_00_10].Ordinamento, 
dbo.[800_00_Index_SM_00_10].ValoreRpt, 
dbo.[800_00_Index_SM_00_10].TipoCert, 
SUM(ValoreRpt) OVER 
 (PARTITION BY dbo.[800_00_Index_SM_00_10].Ordinamento) AS NrAllegato, 
 dbo.[800_00_Index_SM_00_10].Analisi, 
 dbo.[800_00_Index_SM_00_10].Ordinamento AS Ordina, 
 dbo.[800_00_Index_SM_00_10].CodiceRpt, 
 dbo.Certificati.CertRapporto, dbo.Etichette.Allegato, 
 dbo.[800_10_01_AltreLingue].ALAllegato


 FROM ((dbo.[800_00_Index_SM_00_10] 
 INNER JOIN dbo.Certificati ON 
   dbo.[800_00_Index_SM_00_10].CertId = dbo.Certificati.CertId) 
 LEFT JOIN dbo.Etichette   
   ON dbo.Certificati.CertCodLinguaCert = dbo.Etichette.idEti) 
 LEFT JOIN dbo.[800_10_01_AltreLingue] 
   ON dbo.Certificati.CertAltreLingue = 
     dbo.[800_10_01_AltreLingue].IdAltreLingue
 ORDER BY dbo.[800_00_Index_SM_00_10].Ordinamento;

这是我的查询。当我执行它它运行正常,但它给了 "关键字' INSERT'"附近的语法不正确当我尝试将其保存为视图时。

1 个答案:

答案 0 :(得分:0)

这是一个语法错误,因为您无法使用INSERT INTO语句创建视图。

您必须SELECT要查看的表格。

我假设您使用MySQL,请在此处查看语法:http://dev.mysql.com/doc/refman/5.0/en/create-view.html