Click here to Skip to main content
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 3:36am
Edited 16-Jul-12 4:26am
Tim Corey90.7K
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 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 16 Jul 2012
Copyright © CodeProject, 1999-2014
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