<bdo id='5cYRZ'></bdo><ul id='5cYRZ'></ul>
    <tfoot id='5cYRZ'></tfoot>
    <i id='5cYRZ'><tr id='5cYRZ'><dt id='5cYRZ'><q id='5cYRZ'><span id='5cYRZ'><b id='5cYRZ'><form id='5cYRZ'><ins id='5cYRZ'></ins><ul id='5cYRZ'></ul><sub id='5cYRZ'></sub></form><legend id='5cYRZ'></legend><bdo id='5cYRZ'><pre id='5cYRZ'><center id='5cYRZ'></center></pre></bdo></b><th id='5cYRZ'></th></span></q></dt></tr></i><div id='5cYRZ'><tfoot id='5cYRZ'></tfoot><dl id='5cYRZ'><fieldset id='5cYRZ'></fieldset></dl></div>

    <legend id='5cYRZ'><style id='5cYRZ'><dir id='5cYRZ'><q id='5cYRZ'></q></dir></style></legend>

    <small id='5cYRZ'></small><noframes id='5cYRZ'>

      1. 通过 StoredProcedure 搜索每日/每周/每月记录计数

        时间:2023-07-09
        <tfoot id='aN92p'></tfoot>

                <i id='aN92p'><tr id='aN92p'><dt id='aN92p'><q id='aN92p'><span id='aN92p'><b id='aN92p'><form id='aN92p'><ins id='aN92p'></ins><ul id='aN92p'></ul><sub id='aN92p'></sub></form><legend id='aN92p'></legend><bdo id='aN92p'><pre id='aN92p'><center id='aN92p'></center></pre></bdo></b><th id='aN92p'></th></span></q></dt></tr></i><div id='aN92p'><tfoot id='aN92p'></tfoot><dl id='aN92p'><fieldset id='aN92p'></fieldset></dl></div>
              1. <legend id='aN92p'><style id='aN92p'><dir id='aN92p'><q id='aN92p'></q></dir></style></legend>
                  <tbody id='aN92p'></tbody>

                  <bdo id='aN92p'></bdo><ul id='aN92p'></ul>

                  <small id='aN92p'></small><noframes id='aN92p'>

                • 本文介绍了通过 StoredProcedure 搜索每日/每周/每月记录计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 MS SQL Server.我制作了一个名为 SP_Get_CallsLogged 的存储过程.

                  Using MS SQL Server.I have made a Stored Procedure named SP_Get_CallsLogged.

                  我有一个名为 TRN_Call 的表,它有一个名为 CallTime 的列,它是一个 DateTime.

                  I have a table named TRN_Call, and it has one column named CallTime which is a DateTime.

                  我的应用程序中有一个用户输入的网页:-

                  I have a web-page in my application where the User enters:-

                  1. 开始日期(日期时间)

                  结束日期(日期时间)

                  周期(每日/每周/每月)(varchar)(来自 DropDownList)

                  Period (Daily/Weekly/Monthly) (varchar) (from DropDownList)

                  我想根据用户在下拉列表.

                  I want to get the Record Count of those calls in my table TRN_Call on the basis of the specified Period(Daily/Weekly/Monthly) selected by user in the DropDownList.

                  例如

                  StartDate ='1/18/2010 11:10:46 AM'
                  EndDate   ='1/25/2010 01:10:46 AM'
                  Period    =Daily
                  

                  因此,上述日期(开始日期+结束日期)之间的记录计数应该以某种方式出现,以便我可以分别参考这些计数,即以下内容:-

                  So the record count between these above mentioned dates(StartDate+EndDate) should come in a manner so that I can refer to those counts separately i.e. the following:-

                  Date 1/18/2010 Records Found 5
                  Date 1/19/2010 Records Found 50
                  Date 1/20/2010 Records Found 15
                  Date 1/21/2010 Records Found 32
                  Date 1/22/2010 Records Found 12
                  Date 1/23/2010 Records Found 15
                  Date 1/24/2010 Records Found 17
                  Date 1/25/2010 Records Found 32
                  

                  并将这些计数发送到 Web 应用程序,以便这些计数可以在 Crystal Reports 中列出.

                  and send those counts to the Web Application so that these counts could be listed then in the Crystal Reports.

                  推荐答案

                  我将编辑您的存储过程以传递在您的网页中选择的开始日期和结束日期,以便您可以将它们包含在 WHERE子句.

                  I would edit your stored procedure to pass the start date and end date selected in your web page so that you can include them in the WHERE clause.

                  -- Daily
                  SELECT CallTime, COUNT(*) AS 'Records Found'
                  FROM TRN_Call
                  WHERE CallTime BETWEEN @StartDate AND @EndDate
                  GROUP BY CallTime
                  

                  每周可能非常复杂.

                  如果您检查此 link 你会看到一个函数(如下),你可以使用它来帮助你获得每周结果

                  If you check this link you will see a function (below) which you can use to help you get the weekly results

                  例如所以在下面创建函数

                  e.g. So create the function below

                  create function FiscalWeek (@startMonth varchar(2), @myDate datetime)  
                  returns int  
                  as  
                  begin  
                  declare @firstWeek datetime  
                  declare @weekNum int  
                  declare @year int  
                  set @year = datepart(year, @myDate)+1  
                  --Get 4th day of month of next year, this will always be in week 1  
                  set @firstWeek = convert(datetime, str(@year)+@startMonth+'04', 102)  
                  --Retreat to beginning of week  
                  set @firstWeek = dateadd(day, (1-datepart(dw, @firstWeek)), @firstWeek)  
                  while @myDate < @firstWeek --Repeat the above steps but for previous year  
                   begin  
                    set @year = @year - 1  
                    set @firstWeek = convert(datetime, str(@year)+@startMonth+'04', 102)  
                    set @firstWeek = dateadd(day, (1-datepart(dw, @firstWeek)), @firstWeek)  
                   end  
                  set @weekNum = (@year*100)+((datediff(day, @firstweek, @myDate)/7)+1)  
                  return @weekNum  
                  end  
                  

                  现在,您应该能够运行下面应该按周分组的代码.要在日、周或年之间进行选择,您还必须将用户选择的时间段传递给您的存储过程.

                  Now, you should be able to run the code below which should group up by weeks. To choose between if you want Day, Week or Year you will also have to pass period selected by the user to your stored procedure.

                  (ps.还没来得及做一年)

                  (ps. Havent got round to doing year yet)

                  SELECT dbo.FiscalWeek('04', CallTime), dbo.FiscalWeek('04', CallTime)%100 ,  COUNT(*) AS 'Records Found - Weekly'
                  FROM TRN_Call
                  WHERE CallTime BETWEEN @StartDate AND @EndDate
                  GROUP BY dbo.FiscalWeek('04', CallTime), dbo.FiscalWeek('04', CallTime)%100  
                  

                  这篇关于通过 StoredProcedure 搜索每日/每周/每月记录计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <tfoot id='PdWRU'></tfoot>

                    <small id='PdWRU'></small><noframes id='PdWRU'>

                        <bdo id='PdWRU'></bdo><ul id='PdWRU'></ul>

                          <tbody id='PdWRU'></tbody>
                      • <legend id='PdWRU'><style id='PdWRU'><dir id='PdWRU'><q id='PdWRU'></q></dir></style></legend>
                        <i id='PdWRU'><tr id='PdWRU'><dt id='PdWRU'><q id='PdWRU'><span id='PdWRU'><b id='PdWRU'><form id='PdWRU'><ins id='PdWRU'></ins><ul id='PdWRU'></ul><sub id='PdWRU'></sub></form><legend id='PdWRU'></legend><bdo id='PdWRU'><pre id='PdWRU'><center id='PdWRU'></center></pre></bdo></b><th id='PdWRU'></th></span></q></dt></tr></i><div id='PdWRU'><tfoot id='PdWRU'></tfoot><dl id='PdWRU'><fieldset id='PdWRU'></fieldset></dl></div>