Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
SQL
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]
Posted
Updated 16-Jul-12 3:26am
v4
Comments
hari19113 16-Jul-12 8:39am    
Question is not clear. If you want to display details regarding datetime you can use datediff function.

You can use BETWEEN (Transact-SQL)[^]
SQL
Create PROCEDURE ProcedureName
	@startDate datetime,
	@endDate datetime, 
AS
BEGIN 
SELECT * FROM  TableName
WHERE
     YourDate BETWEEN @startDate AND @endDate 
END
 
Share this answer
 
Your procedure will look something like this.

SQL
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900