【问题标题】:Getting no. of rows affected after running select query in SQL Server 2005没有。在 SQL Server 2005 中运行选择查询后受影响的行数
【发布时间】:2010-12-05 08:13:13
【问题描述】:

以下是我的查询

select    
@monNameStr as [MName],             
IsNull(count(c.AssignmentID),0),                
IsNull(sum(s.ACV),0),               
IsNull(sum(s.GrossReturn),0),               
IsNull(sum(s.NetReturn),0),             
IsNull(avg(a.Total),0)          
FROM

dbo.Assignment_ClaimInfo c,             
dbo.Assignment_SettlementInfo s,                
dbo.Assignment_AdvCharges a         

Where
c.Assignmentid=s.Assignmentid and               
s.Assignmentid=a.Assignmentid and               
a.Assignmentid in                   

(select AssignmentID from dbo.Assignment_ClaimInfo                  
where (upper(InsuranceComp)=upper(@CompName) or upper(@CompName)='ALL COMPANIES') 
and (DateName(month,DATEADD(month, 0, DOFileClosed))+' '
+cast(year(DATEADD(month, 0, DOFileClosed)) as varchar)=@monNameStr))
Group By c.InsuranceComp
Order By c.InsuranceComp

where @monNameStr is calculated date field like 'October 2009'

我需要知道的没有。受此选择查询影响的记录数。

我不需要使用 COUNT() 函数将此查询嵌套到另一个查询。

感谢您的宝贵帮助。

【问题讨论】:

    标签: sql-server select


    【解决方案1】:

    将@@ROWCOUNT 捕获到一个变量中,因为每次选择它时它都会改变值:

    DECLARE @Rows   int
    
    ---your query here
    
    SELECT @Rows=@@ROWCOUNT
    

    然后您可以根据需要使用它,如@Rows

    【讨论】:

      【解决方案2】:

      您可以在查询运行后检查@@ROWCOUNT 的值。请参阅http://technet.microsoft.com/en-us/library/ms187316.aspx 了解更多信息。

      【讨论】:

        【解决方案3】:

        【讨论】:

          【解决方案4】:
          You can just use `@@ROWCOUNT` to get the records affected/returned
          
          DECLARE @rowsreturned INT
          SET @rowsreturned = @@ROWCOUNT
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2015-06-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多