我给你两种简单的方法:
1.
过程
CREATE PROCEDURE cyPFindWaitExecSO
----按货品编码查出没有执行销售订单(不包括 CANCEL 作废, stoped 中止)
@GOODSCODE VARCHAR(100)
AS
SELECT SO.WDATE,so.BILLCODE,a.QTY,a.EXEQTY,a.QTY-a.EXEQTY WaitExec,c.CLIENTNO,a.USERDEF1
FROM
(SELECT * FROM S_ORDERd WHERE EXEQTY< qty AND STOPED=0 AND canceled=0 AND GOODSID=
(SELECT GOODSID FROM GOODS g WHERE CODE = @GOODSCODE))AS a
LEFT JOIN S_ORDER so ON so.BILLID= A.BILLID
LEFT JOIN CLIENT c ON c.CLIENTID=so.CLIENTID
调用
cyPFindWaitExecSO是一个查询存储过程, GOODSCODE 是一个参数
Tsql = "exec cyPFindWaitExecSO '" & goodscode & "'"
Rs.Open Tsql, DBcn1
cyPFindWaitExecSO是一个查询存储过程, GOODSCODE 是一个参数
2. 过程
CREATE PROC ConfirmIDcardUsering
@card_id NVARCHAR(16),
@emp_id NVARCHAR(12),
@outStr NVARCHAR(50) OUTPUT
AS
IF EXISTS(SELECT Etime FROM KQID k WHERE k.card_id=@card_id AND etime IS NULL)
SET @outStr = '卡在正常使用中'
ELSE if exists(SELECT Etime FROM KQID k WHERE k.emp_id= @emp_id AND etime IS NULL)
SET @outStr = '该员工已有卡在用'
else
SET @outStr= ''
GO
调用:
Set Cmd = New ADODB.Command
With Cmd
.ActiveConnection = dbcn '数据连接字符串
.CommandType = 4
.CommandText = "ConfirmIDcardUsering" '过程名'
.Parameters.Item("@card_id").Value = Card_id '参数一'
.Parameters.Item("@emp_id").Value = emp_id '参数二'
.Execute
TestS = .Parameters.Item("@outStr").Value '反回的函数'
End With
Set Cmd = Nothing