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.
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-062010-102009-06How 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 Table1WHERE Intake = CONVERT(CHAR(7), DATEADD(MONTH, -2, GETDATE()), 120) N 56°04'39.26"E 12°55'05.63" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-11 : 02:36:45
|
1 Always use proper DATETIME datatype to store dates2 If you dont want day part, you can store them with first day of month so that it is easy for date calculationsMadhivananFailing to plan is Planning to fail |
|
|
|
|
|