当我执行查询时会抛出错误CERATE VIEW必须是批处理中唯一的语句。如何在SQL Server中在我的方案中创建VIEW?
这里是我的查询
select ID,StoreID,TotalQtyParent into #tempQuantity
From
(
select ID,'1001' StoreID,Sum([TotalQtyParent]) TotalQtyParent
FROM [HQMatajer].[dbo].[ItemRelationQty]
where StoreID='1001' and TotalQtyParent is not null
group by ID
Union
select ID,'StoreAll' StoreID,sum([TotalQtyParent]) TotalQtyParent
FROM [HQMatajer].[dbo].[ItemRelationQty]
where StoreID<>'1001' and TotalQtyParent is not null
group by ID
) totalquantity
SELECT
ID,
[1001] AS WHS,
[StoreAll] AS Store
into #singleRow
FROM
(
SELECT
ID, StoreID, TotalQtyParent
FROM #tempQuantity
) AS TotalQty
PIVOT
(
SUM(TotalQtyParent)
FOR StoreID IN ([1001], [StoreAll])
) AS PivotTable
order by ID
BEGIN
CREATE VIEW vwSummaryWHS AS //Here is my VIEW
SELECT
item.ItemLookupCode,item.Description,WHS,Store,item9days.QtySold NineDays,item30days.QtySold ThirtyDays
FROM
#singleRow sr
LEFT JOIN HQMatajer.dbo.Item item on item.id=sr.ID
LEFT JOIN
(
select itemid,sum(qtysold) [QtySold]
from [HQMatajer].[dbo].[JC_ItemDSP10days]
group by ItemID
) item9days on item9days.ItemID = sr.ID
LEFT JOIN
(
select itemid,sum(qtysold) [QtySold]
from [HQMatajer].[dbo].[JC_ItemDSP30Days]
group by ItemID
)item30days on item30days.ItemID = sr.ID
END
drop table #tempQuantity
drop table #singleRow
我试图创建在查询开始的一个视图中。但它显示了同样的错误之前一样,你的CREATE VIEW语句之后
是的。我知道了。刚才我看到了这个错误 –