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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql add month

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2010-06-10 : 11:38:25
Hi, I have a field call Intake in my table1. The Intake field datatype is varchar. The sample data is:

Intake (Varchar)
2010-06
2010-10
2009-06


How can I select the intake which is 3 month ago from current month since the datatype for intake is varchar instead of datetime... I know I can use addmonth, but not sure how to write it.Can anyone guide me?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-10 : 12:02:31
SELECT * FROM Table1
WHERE Intake = CONVERT(CHAR(7), DATEADD(MONTH, -2, GETDATE()), 120)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-11 : 02:36:45
1 Always use proper DATETIME datatype to store dates
2 If you dont want day part, you can store them with first day of month so that it is easy for date calculations

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -