Click here to Skip to main content
11,640,211 members (67,877 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: database
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]
Posted 16-Jul-12 2:36am
Edited 16-Jul-12 3:26am
Tim Corey100.1K
v4
Comments
hari19113 at 16-Jul-12 8:39am
   
Question is not clear. If you want to display details regarding datetime you can use datediff function.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 CPallini 239
1 Suvendu Shekhar Giri 215
2 Mika Wendelius 210
3 OriginalGriff 165
4 Sergey Alexandrovich Kryukov 139


Advertise | Privacy | Mobile
Web03 | 2.8.150731.1 | Last Updated 16 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100