S
sdldp
Unregistered / Unconfirmed
GUEST, unregistred user!
[?]定义一个存储过程,代码如下:
CREATE PROCEDURE QueryJiaTai @starttime char(19),@houseid int AS
DECLARE @request char(19)
DECLARE @opensum int
DECLARE @destsum int
SET @opensum=(SELECT COUNT(insymbol) AS total FROM opentables WHERE starttime=@starttime)
SET @request=(SELECT request FROM opentables WHERE starttime=@starttime AND destine=1)
SET @destsum=(SELECT COUNT(insymbol) AS total FROM desttable WHERE request=@request)
IF @opensum>0 AND @destsum=0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM opentables WHERE starttime=@starttime)
ELSE IF @destsum>0 AND @opensum=0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM desttable WHERE request=@request)
ELSE IF @opensum>0 AND @destsum>0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM opentables WHERE starttime=@starttime)
AND insymbol NOT IN (SELECT insymbol FROM desttable WHERE request=@request)
最后一种情况下,执行不正确,不知道如何实现最后这种情况?
CREATE PROCEDURE QueryJiaTai @starttime char(19),@houseid int AS
DECLARE @request char(19)
DECLARE @opensum int
DECLARE @destsum int
SET @opensum=(SELECT COUNT(insymbol) AS total FROM opentables WHERE starttime=@starttime)
SET @request=(SELECT request FROM opentables WHERE starttime=@starttime AND destine=1)
SET @destsum=(SELECT COUNT(insymbol) AS total FROM desttable WHERE request=@request)
IF @opensum>0 AND @destsum=0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM opentables WHERE starttime=@starttime)
ELSE IF @destsum>0 AND @opensum=0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM desttable WHERE request=@request)
ELSE IF @opensum>0 AND @destsum>0
SELECT id
FROM tables
WHERE houseid=@houseid
AND insymbol NOT IN (SELECT insymbol FROM opentables WHERE starttime=@starttime)
AND insymbol NOT IN (SELECT insymbol FROM desttable WHERE request=@request)
最后一种情况下,执行不正确,不知道如何实现最后这种情况?