如何在 Advantage 数据库中的日期上添加 100 年

发布于 2024-09-25 06:56:35 字数 122 浏览 3 评论 0原文

我的 Advantage 数据库中有一堆记录的结束日期为 1909 年,而不是 2009 年。如何运行更新语句来为每个日期添加 100 年? (优点是告诉我没有“str()”函数,它不会让我将月份(mydate)与“/”连接起来。

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 "/".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一紙繁鸢 2024-10-02 06:56:35

您可以使用以下内容

UPDATE mytable
SET mydate =  CAST( TIMESTAMPADD( SQL_TSI_YEAR, 100, datefield ) as SQL_DATE )
WHERE YEAR( datefield ) = 1909

(如果您有时间戳字段而不是日期字段,您可以省略 CAST ... AS SQL_DATE)


要连接,您必须连接字符串以更改为可以使用 CAST 或 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

(如果您有时间戳字段而不是日期字段,您可以省略 CAST ... AS SQL_DATE,但随后您需要重新添加时间)

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)

无戏配角 2024-10-02 06:56:35

我的 SQL 很生锈,但 Advantage Database 似乎支持 DATEADD。所以...呃...类似的事情?

UPDATE mytable
SET field = DATEADD(Year, 100, field)
FROM mytable
WHERE field < '19100101'

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'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文