一个SQL语句的问题,急死我了,请帮帮忙!!! (30分)

  • 主题发起人 主题发起人 sdldp
  • 开始时间 开始时间
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)
最后一种情况下,执行不正确,不知道如何实现最后这种情况?
 
怎么不正确?
 
在最后一种情况下,实际上有符合条件的记录,可是结果却返回空
 
是不是你的条件不对
 
是不是要注意一下运算符的优先级.
 

Similar threads

I
回复
0
查看
596
import
I
I
回复
0
查看
738
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部