Seperti yang dikatakan kesalahan, CREATE VIEW
pernyataan harus menjadi satu-satunya pernyataan dalam kumpulan kueri.
Anda memiliki dua opsi dalam skenario ini, tergantung pada fungsionalitas yang ingin Anda capai:
-
Tempatkan
CREATE VIEW
kueri di awalCREATE VIEW showing as select tradename, unitprice, GenericFlag from Medicine; with ExpAndCheapMedicine(MostMoney, MinMoney) as ( select max(unitprice), min(unitprice) from Medicine ) , findmostexpensive(nameOfExpensive) as ( select tradename from Medicine, ExpAndCheapMedicine where UnitPrice = MostMoney ) , findCheapest(nameOfCheapest) as ( select tradename from Medicine, ExpAndCheapMedicine where UnitPrice = MinMoney )
-
Gunakan
GO
setelah CTE dan sebelumCREATE VIEW
permintaan-- Opsi #2
with ExpAndCheapMedicine(MostMoney, MinMoney) as ( select max(unitprice), min(unitprice) from Medicine ) , findmostexpensive(nameOfExpensive) as ( select tradename from Medicine, ExpAndCheapMedicine where UnitPrice = MostMoney ) , findCheapest(nameOfCheapest) as ( select tradename from Medicine, ExpAndCheapMedicine where UnitPrice = MinMoney ) GO CREATE VIEW showing as select tradename, unitprice, GenericFlag from Medicine;