【求助】一段创建View视图的sql语句,请问怎样改正?求大神!
DECLARE @Price NUMERIC(19,6)
CREATE VIEW TestCPS_VI_StockQuery
AS
SELECT m1.itemcode,m1.ItmsGrpCod,m1.CodeBars,m1.ItemName,m1.U_DV,m1.U_DC,
m1.U_004,m1.U_006,m1.UserText,@Price = SELECT (m2.OnHand - m2.IsCommited + m2.OnOrder),
m3.WhsName
FROM dbo.TextOITM AS m1 INNER JOIN dbo.TestOITW AS m2 ON m1.ItemCode = m2.ItemCode
INNER JOIN dbo.OWHS m3 ON m2.WhsCode = m3.WhsCode
这段sql在添加@Price = SELECT (m2.OnHand - m2.IsCommited + m2.OnOrder)之前是正确的,但是添加上了之后就错了,请问怎样改正
------解决方案--------------------视图不能用变量,只有存储过程可以
CREATE VIEW TestCPS_VI_StockQuery
AS
SELECT m1.itemcode,m1.ItmsGrpCod,m1.CodeBars,m1.ItemName,m1.U_DV,m1.U_DC,
m1.U_004,m1.U_006,m1.UserText,(SELECT (m2.OnHand - m2.IsCommited + m2.OnOrder)) as Price,
m3.WhsName
FROM dbo.TextOITM AS m1 INNER JOIN dbo.TestOITW AS m2 ON m1.ItemCode = m2.ItemCode
INNER JOIN dbo.OWHS m3 ON m2.WhsCode = m3.WhsCode
这样就可以了