日期:2014-05-17 浏览次数:20664 次
CREATE VIEW dbo.cg_purchase AS SELECT a.[ID], a.DeptID,h._Name as Dept,a.BillID, Type=CASE WHEN a.Type=1 THEN '采购' ELSE '退货' END, _Date=convert(char(10),a._Date,120), a.OperatorID, a.ProvID, a.StockID, ChkDate=convert(char(10),a.ChkDate,120), a.ChkOperatorID,Status=CASE WHEN a.Status=1 THEN '待审核' ELSE '已审核' END, a.Remark, b.JobNO AS OperatorNO, b._Name AS Operator, e.SupNO, e._Name AS Provider, d._Name AS StockName, c.JobNO AS ChkOperatorNO, a.InCash, c._Name AS ChkOperator,e.pyCode as ProviderCode,a.OperationID,dbo.aa_gettotalprofit(a.[ID],6) as Total,dbo.aa_gettotalprofit(a.[ID],9) as GoodsAmount,a.OperationBill FROM dbo.Purchase a LEFT OUTER JOIN dbo.StaffList b ON a.OperatorID = b.[ID] LEFT OUTER JOIN dbo.StaffList c ON a.ChkOperatorID = c.[ID] LEFT OUTER JOIN dbo.StockList d ON a.StockID = d.[ID] LEFT OUTER JOIN dbo.SupplierList e ON a.ProvID = e.[ID] LEFT OUTER JOIN dbo.BranchList h ON a.DeptID=h.[ID]
------解决方案--------------------
就是在sql查询的时候就多表查询
SELECT t1.id,t2.name from [idtable] t1
join [nametable] on t1.id=t2.id
这样返回的就是两个表的连接结果