SQL Between Stored Proc
-
Hi! Can someone please tell me how would I go about creating a Stored Proc to select records between dates? I have 2 variables, date1 and date2 I want to create a stored proc as follows: select * from table between date1 and date2 where the dates are variables in the stored proc.
Illegal Operation
-
Hi! Can someone please tell me how would I go about creating a Stored Proc to select records between dates? I have 2 variables, date1 and date2 I want to create a stored proc as follows: select * from table between date1 and date2 where the dates are variables in the stored proc.
Illegal Operation
select * from table where datecolumn between date1 and date2 e.g.
declare @t table(activity varchar(10),datecol datetime)
insert into @t
select 'activity1', '2009-12-01' union all
select 'activity2','2009-12-02' union all
select 'activity3','2009-12-15' union all
select 'activity4','2010-01-02' union all
select 'activity5','2009-12-31'Declare 2 date variables
declare @date1 datetime,@date2 datetime
set @date1 = '2009-12-01'
set @date2 = '2009-12-15'I want to select records between 1st Dec 2009 to 15th Dec 2009. Query:
select * from @t
where datecol between @date1 and @date2Output: activity datecol
activity1 2009-12-01 00:00:00.000
activity2 2009-12-02 00:00:00.000
activity3 2009-12-15 00:00:00.000Niladri Biswas
-
Hi! Can someone please tell me how would I go about creating a Stored Proc to select records between dates? I have 2 variables, date1 and date2 I want to create a stored proc as follows: select * from table between date1 and date2 where the dates are variables in the stored proc.
Illegal Operation
CREATE PROCEDURE usp_GetDataFromDateRange(
@Start DATETIME,
@End DATETIME
)
AS
BEGIN
SET NOCOUNT ON;SELECT * FROM MyTable
WHERE DateCol BETWEEN @Start AND @EndRETURN
END
I don't speak Idiot - please talk slowly and clearly 'This space for rent' Driven to the arms of Heineken by the wife