VB中这样: mcmd.ActiveConnection = cn mcmd.CommandType = adCmdStoredProc mcmd.CommandText = "proc_RetrieveListSome" mcmd.CommandTimeout = gTimeOut With mcmd Set mPara = .CreateParameter("TypeName", adVarChar, adParamInput, 50, Trim(TypeName)) .Parameters.Append mPara Set mPara = .CreateParameter("ProductID", adInteger, adParamInput, 38, m_CProduct.ProductID) .Parameters.Append mPara End With ' Debug.Print rs.State Set rs = mcmd.Execute() 存储过程: CREATE PROCEDURE proc_RetrieveListSome @TypeName nvarchar(50), @ProductID decimal asset nocount onbegin declare @NodeID as decimal declare @PartID as decimalif exists(select t.orderID from tm_product_tree t inner join tm_part_info i on i.partid=t.partid where i.PartName=@TypeName and t.ProductID=@ProductID) begin print 'exists' set @NodeID=(select t.orderID from tm_product_tree t inner join tm_part_info i on i.partid=t.partid where i.PartName=@TypeName and t.ProductID=@ProductID) end ---如果存在 exec proc_treePartinfo2 @NodeID,@ProductID select b.PartPicNo,b.PartName,r.Cut,r.RoughSize,r.MaterialSpecName, r.Collet,r.Length,r.RoughCount,r.NetWeight,r.UsingRate,r.IsPressed, r.comment,r.MaterialID,c.PartCount,r.Weight,r.IsSpare,r.PartIndex,r.Technology, c.PartTypeID , r.ration, c.OrderID, r.EditStamp, c.ProductID, c.PartIndex1 from temp_res as a left join tm_product_tree as c on a.orderid=c.orderid left join tm_part_info as b on b.partid=c.partid left join tm_part_ration as r on r.orderid=c.orderid order by a.op,cast(c.parttypeid as int),a.fatherorderid,b.partNameset nocount off end GO 大家帮忙分析一下问题吧,谢谢
mcmd.ActiveConnection = cn
mcmd.CommandType = adCmdStoredProc
mcmd.CommandText = "proc_RetrieveListSome"
mcmd.CommandTimeout = gTimeOut
With mcmd
Set mPara = .CreateParameter("TypeName", adVarChar, adParamInput, 50, Trim(TypeName))
.Parameters.Append mPara
Set mPara = .CreateParameter("ProductID", adInteger, adParamInput, 38, m_CProduct.ProductID)
.Parameters.Append mPara
End With
' Debug.Print rs.State
Set rs = mcmd.Execute()
存储过程:
CREATE PROCEDURE proc_RetrieveListSome
@TypeName nvarchar(50),
@ProductID decimal
asset nocount onbegin
declare @NodeID as decimal
declare @PartID as decimalif exists(select t.orderID from tm_product_tree t inner join tm_part_info i on i.partid=t.partid where i.PartName=@TypeName and t.ProductID=@ProductID)
begin
print 'exists'
set @NodeID=(select t.orderID from tm_product_tree t inner join tm_part_info i on i.partid=t.partid where i.PartName=@TypeName and t.ProductID=@ProductID)
end
---如果存在
exec proc_treePartinfo2 @NodeID,@ProductID
select b.PartPicNo,b.PartName,r.Cut,r.RoughSize,r.MaterialSpecName,
r.Collet,r.Length,r.RoughCount,r.NetWeight,r.UsingRate,r.IsPressed,
r.comment,r.MaterialID,c.PartCount,r.Weight,r.IsSpare,r.PartIndex,r.Technology,
c.PartTypeID , r.ration, c.OrderID, r.EditStamp, c.ProductID, c.PartIndex1
from temp_res as a
left join tm_product_tree as c on a.orderid=c.orderid
left join tm_part_info as b on b.partid=c.partid
left join tm_part_ration as r on r.orderid=c.orderid
order by a.op,cast(c.parttypeid as int),a.fatherorderid,b.partNameset nocount off
end
GO
大家帮忙分析一下问题吧,谢谢