Home > Mobile >  Error "'CREATE VIEW' must be the first statement in a query batch." and "In
Error "'CREATE VIEW' must be the first statement in a query batch." and "In

Time:12-29

I'm getting error in this below line,

CREATE VIEW reorder_view  
AS 
SELECT a.S_CODE AS S_CODE, 
       a.CODE AS CODE, 
       a.PRCT_TYPE AS PRCT_TYPE, 
       b.VENR_CODE AS VENR_CODE, 
       b.MATERAL_CODE AS MATERAL_CODE, 
       b.ORDER_LEVEL AS ORDER_LEVEL, 
       c.SUPPL_NAME AS SUPPL_NAME, 
       sum(a.QTY) AS TOTAL_QTY 
FROM  ((storage a 
       join supplier_items b) 
       join supplier_info c) 
WHERE  b.MATERAL_CODE = a.S_CODE 
AND    b.VENDR_CODE = c.VENDR_CODE 
GROUP BY a.S_CODE, 
         c.VENDR_CODE 
HAVING TOTAL_QTY <= b.ORDER_LEVEL ;

error msg:

'CREATE VIEW' must be the first statement in a query batch.,

Incorrect syntax near ')

CodePudding user response:

The easy way to fix this would be to use GO after the last statement.

--previous statement
GO
create view v1 as 
select *
  from table;
GO

CodePudding user response:

You have to applying correct join syntax as blow:

CREATE VIEW Reorder_view  
AS 
SELECT a.SAP_CODE AS SAP_CODE, 
       a.CODE AS CODE, 
       a.PRODUCT_TYPE AS PRODUCT_TYPE, 
       b.VENDOR_CODE AS VENDOR_CODE, 
       b.MATERIAL_CODE AS MATERIAL_CODE, 
       b.REORDER_LEVEL AS REORDER_LEVEL, 
       c.SUPPLIER_NAME AS SUPPLIER_NAME, 
       sum(a.QTY) AS TOTAL_QTY 
FROM  fifo_storage a 
       join fifo_supplier_items b on a.ColumnName_a=b.ColumnName_b
       join fifo_supplier_info c on a.ColumnName_a=c.ColumnName_c
WHERE  b.MATERIAL_CODE = a.SAP_CODE 
AND    b.VENDOR_CODE = c.VENDOR_CODE 
GROUP BY a.SAP_CODE, 
         c.VENDOR_CODE 
HAVING TOTAL_QTY <= b.REORDER_LEVEL ;
  • Related