I have a bunch of records in my Advantage Database that ended up with the year 1909, rather than 2009. How can run an update statement that will add 100 years to each of these dates? (Advantage is telling me that there is no "str()" function, and it won't let me concatenate month(mydate) with "/".
A:
My SQL is rusty but Advantage Database seems to support DATEADD. So... uh... something like this?
UPDATE mytable
SET field = DATEADD(Year, 100, field)
FROM mytable
WHERE field < '19100101'
Hostile Fork
2010-09-27 19:22:49
dateadd() is giving me an error...perhaps that a V10 thing? (I'm still on 9.1)
Chris Curvey
2010-09-28 12:33:25
+4
A:
You could use the following
UPDATE mytable
SET mydate = CAST( TIMESTAMPADD( SQL_TSI_YEAR, 100, datefield ) as SQL_DATE )
WHERE YEAR( datefield ) = 1909
(if you have a timestamp field and not a date field you can leave out the CAST ... AS SQL_DATE)
To concatenate you must concatenate strings to change to a string you can use CAST or CONVERT
UPDATE mytable
SET datefield = CAST ( TRIM( CAST( MONTH(datefield) AS SQL_CHAR ) ) + '/' + TRIM( CAST( DAYOFMONTH( datefield ) AS SQL_CHAR ) ) + '/2009' AS SQL_DATE )
WHERE YEAR( datefield ) = 1909
(if you have a timestamp field and not a date field you can leave out the CAST ... AS SQL_DATE, but then you need to re-add in the time)
Edgar
2010-09-27 20:17:18