可能需要光标

发布于 2024-10-08 18:58:10 字数 356 浏览 1 评论 0原文

我有一个明显简单的问题,但找不到好的解决方案,所以我将感谢社区的帮助。

假设我的表包含三列:DealID、TransID 和 Number。假设我有 4 行,DealID 的值在所有 4 行中都相同,TransID 在每行中具有不同的值(并且数据按此列升序排列),并且 Number 在第一行中具有一些值,而在所有其他行中具有 NULL 。

我的简单问题是:对于确切的 Trans_Id,如何确定存储过程中所有大于当前的 Trans_Id 值,Number 的所有值是否均为 NULL?即我想知道对于大于当前 Trans_Id 值的任何其他 Trans_Id 是否有任何不同于 NULL 的 Number 值。

提前TnX!

内马尼亚

I have one obviously simple problem, but cannot find good solution, so I would appreciate community help.

Let's say that my table has three columns: DealID, TransID and Number. And let's say that I have 4 rows, value for DealID is same in all 4 rows, TransID has different value in each row (and data is ordered ascending by this column) and Number has some value in first row and NULLs in all other rows.

My simple question is: For exact Trans_Id, how to determine in sproc for all Trans_Id values greater than current, are all values for Number NULLs? I.e. I want to know is there any Number value that is different from NULL for any other Trans_Id that is greater than current Trans_Id value.

TnX in advance!

Nemanja

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲜肉鲜肉永远不皱 2024-10-15 18:58:11

这个怎么样:

SELECT * FROM mytable
WHERE DealID = (SELECT DealID FROM mytable WHERE TransID = @transID)
AND TransID > @transID
AND Number IS NOT NULL

How's this:

SELECT * FROM mytable
WHERE DealID = (SELECT DealID FROM mytable WHERE TransID = @transID)
AND TransID > @transID
AND Number IS NOT NULL
玉环 2024-10-15 18:58:11

尝试这样的事情(我假设 dealID 是参数之一):

-- return 1 if there not null numbers for given @dealID and @tranID
CREATE PROC checkNullNumbers (
   @dealID INT,
   @transID INT
)
AS 
BEGIN
   DECLARE 
      @result INT

   SELECT TOP 1 1
   FROM 
    mytable
   WHERE
     dealID = @dealID
     AND transID > @transID
     AND number IS NOT NULL

   SET @result = @@ROWCOUNT

   SELECT @result AS result
END

Try something like this (I assume dealID is one of parameters):

-- return 1 if there not null numbers for given @dealID and @tranID
CREATE PROC checkNullNumbers (
   @dealID INT,
   @transID INT
)
AS 
BEGIN
   DECLARE 
      @result INT

   SELECT TOP 1 1
   FROM 
    mytable
   WHERE
     dealID = @dealID
     AND transID > @transID
     AND number IS NOT NULL

   SET @result = @@ROWCOUNT

   SELECT @result AS result
END
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文