Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 input parameter in keyword between

Author  Topic 

Adianjali
Starting Member

7 Posts

Posted - 2011-01-07 : 05:12:33
SELECT registeredby_date
FROM trn_ticket
WHERE registeredby_date
BETWEEN 1-Jan-2011 AND 5-Jan-2011
Above is the query.
But i want the above hard coded date to given through user input as parameter so that i can get registeredby_date between any of the date given by user(want input parameter)
Can anyone help me for the same



arjun.s

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-07 : 07:10:30
Create Procedure xyz
(@date1 datetime,@date2 Datetime
)
as
SELECT registeredby_date
FROM trn_ticket
WHERE registeredby_date
BETWEEN @date1 AND @date2

once the stored procedure is created just call it as;

exec xyz '1-Jan-2011','5-Jan-2011'

Cheers!
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 01:44:41
please keep in mind that if registeredby_date has time part it will cause all records created after midnight of @date2 to be filtered out by BETWEEN. so this might prove better
[code]
WHERE registeredby_date >= @date1
AND registeredby_date < @date2+1
[code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -