存储Proc的日期持续时间 [英] Store Proc for dates duration
问题描述
我在数据库中有一个只有一个日期的表,我正在编写存储过程,我想在其中指示开始日期和结束日期以显示两个日期之间的某些信息.我该怎么办?
我想做的是在数据A和日期B(订单日期)之间,完成了多少销售.
谢谢.
如果我正确的话,我需要通过使用Where子句(通过将Startdate和end date作为参数)来找到它.
非常感谢你.
我的查询如下:
I have table in Database which has only one date and I am process to write store procedure in which I want to indicate startdate and end date to show certain information between two dates. How can I do that?
What I am trying to do is between to Data A and Date B (Order date), how much sales I have done.
Thank you.
If I correct I need to find this by using Where clause by utilizing Startdate and end date as a parameter.
Thank you very much.
Query I have is as follow:
CREATE TABLE [dbo].[sales](
[stor_id] [char](4) NOT NULL,
[ord_num] [varchar](20) NOT NULL,
[ord_date] [datetime] NOT NULL,
[qty] [smallint] NOT NULL,
[payterms] [varchar](12) NOT NULL,
[title_id] [dbo].[tid] NOT NULL,
CONSTRAINT [UPKCL_sales] PRIMARY KEY CLUSTERED
(
[stor_id] ASC,
[ord_num] ASC,
[title_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
推荐答案
您可以使用 BETWEEN(Transact-SQL) [
You can use BETWEEN (Transact-SQL)[^]
Create PROCEDURE ProcedureName
@startDate datetime,
@endDate datetime,
AS
BEGIN
SELECT * FROM TableName
WHERE
YourDate BETWEEN @startDate AND @endDate
END
您的过程将如下所示.
Your procedure will look something like this.
Create PROCEDURE [dbo].[DummyProc]
@startDate datetime,
@endDate datetime,
AS
BEGIN
SELECT *
FROM [dbo].[rl_master]
where
phy_confirmed >= @startDate AND
phy_confirmed <= @endDate
END
注意:使用此参考创建您自己的过程.这只是演示如何完成.
NOTE: use this for reference to create your own procedure. this is only to demonstrate how it can be done.
这篇关于存储Proc的日期持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!