我有这四个表:
class Parent extends React.Component{
state = {departure : ''}
setDeparture = departure => this.setState({ departure })
render(){ <Child setDeparture={this.setDeparture} /> }
}
const Child = ({setDeparture}) => <button onClick={() => setDeparture('foo')}>Click</button>
:产品ID,名称,价格,类别ID tblProducts
:类别ID,名称tblCategories
:订单编号,日期,总计tblOrders
:OrderDetailsId,OrderId,ProductId,数量,价格我想创建一个过程tblOrderDetails
。
我希望在我的应用中返回类型为复杂类型,并且我希望这些列:
OrderDetails_SelectByOrderId
我尝试了所有操作,但无法获得结果的类别名称。
答案 0 :(得分:2)
这应该做到。如果CategoryNAME返回为null,则说明您正在进行LEFT OUTER连接,并且存在参照完整性问题。
CREATE PROCEDURE usp_OrderDetails_SelectByOrderId
@OrderID INT
AS
BEGIN
SELECT P.ProductId,
OD.Qty,
P.Price,
C.NAME AS CategoryNAME
FROM tblProducts P
INNER JOIN tblCategories C ON P.CategoryId = C.CategoryId
INNER JOIN tblOrderDetails OD ON P.ProductId = OD.ProductId
INNER JOIN tblOrders O ON OD.OrderId = O.OrderId
WHERE O.OrderId = @OrderId
END