developer77
Programmer
Hello everyone,
I've pasted a part of my stored procedure below:
-- Declare month, year
DECLARE @Month int
DECLARE @Year int
-- Initialize SQL environment
SET NOCOUNT ON
SET CONCAT_NULL_YIELDS_NULL OFF
-- Strip off the time part of the date.
SELECT @Date = substring(convert(varchar, @Date, 100), 1, 12)
SELECT @Month = Month(@Date), @Year = Year(@Date)
-- Get information
SELECT P.Firstname, P.Lastname, P.SSN, P.Address, J.Title,
J.Salary
FROM People P, Job J
WHERE P.ID = J.PeopleID
AND Month(J.HireDate) = @Month ) AND ( Year(J.HireDate) = @Year )
Right now it's looking at one date parameter @Date which is a datetime datatype. I need to add another parameter for the end date so that this we can query by a date range. I plan to add another paramter called EndDate and strip off the time like the @Date parameter. However, I'm not sure how to do a between for month and year. For example right now I have it comparing the parameter month and year to the HIREDATE month and year. How do I do a between for this when I add another end date parameter? Thanks in advance for your help.
I've pasted a part of my stored procedure below:
-- Declare month, year
DECLARE @Month int
DECLARE @Year int
-- Initialize SQL environment
SET NOCOUNT ON
SET CONCAT_NULL_YIELDS_NULL OFF
-- Strip off the time part of the date.
SELECT @Date = substring(convert(varchar, @Date, 100), 1, 12)
SELECT @Month = Month(@Date), @Year = Year(@Date)
-- Get information
SELECT P.Firstname, P.Lastname, P.SSN, P.Address, J.Title,
J.Salary
FROM People P, Job J
WHERE P.ID = J.PeopleID
AND Month(J.HireDate) = @Month ) AND ( Year(J.HireDate) = @Year )
Right now it's looking at one date parameter @Date which is a datetime datatype. I need to add another parameter for the end date so that this we can query by a date range. I plan to add another paramter called EndDate and strip off the time like the @Date parameter. However, I'm not sure how to do a between for month and year. For example right now I have it comparing the parameter month and year to the HIREDATE month and year. How do I do a between for this when I add another end date parameter? Thanks in advance for your help.