February 1, 2010 at 11:51 am
Hi,
i know the syntax dateadd(month,3,datefield) which will add 3 months and you can only see one month..
but i want a syntax to see all next 3 months of data .
Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e
2010-02-01,
2010-03-01,
2010-04-01.
February 1, 2010 at 11:57 am
itskumar2004 (2/1/2010)
Hi,i know the syntax dateadd(month,3,datefield) which will add 3 months and you can only see one month..
but i want a syntax to see all next 3 months of data .
Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e
2010-02-01,
2010-03-01,
2010-04-01.
assuming you have a table with that datetime filed, you would want to use a BETWEEN statement to get everything between teh range you are looking for:
ie
SELECT * FROM MYTABLE
--betweent eh date and the date plus three months
WHERE MYDATEFIELD BETWEEN @DateParameter and dateadd(month,3,@DateParameter )
Lowell
February 1, 2010 at 12:13 pm
hi,
it should fetch the next 3 months for my given date which is going to be a parameter in my stored procedure ,for whatever date we give it should fetch data for next 3 months...i dont know the range
i.e if datefield is the column i have in the table and if datefield=2010-01-01 which is going to be a parameter it should fetch data for next 3 months..
February 1, 2010 at 12:21 pm
What requirement cannot be achieved with Lowells solution?
The BETWEEN clause will "fetch data for next 3 months" as per your requirement.
If you need more assistance you might want to provide more detailed information.
Repeating what you already posted doesn't help...
February 1, 2010 at 12:51 pm
I am sorry for my confusion.i got the results using the syntax thanks for that ...
My results are including the datefield column below(2010-01-01) ,Can you also tell me how should i exclude it and only get next 3 months of data
Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e
2010-02-01,
2010-03-01,
2010-04-01.
Please correct me if i am wrong..
February 1, 2010 at 1:01 pm
Using Lowells sample:
SELECT * FROM MYTABLE
--betweent eh date and the date plus three months
--WHERE MYDATEFIELD BETWEEN @DateParameter and dateadd(month,3,@DateParameter )
WHERE MYDATEFIELD > DateParameter
AND MYDATEFIELD <=dateadd(month,3,@DateParameter )
February 1, 2010 at 1:07 pm
Thanks a lot ..
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply