编写一个查询,从包含日期的表中提取所有字段

发布于 2024-12-10 01:19:48 字数 169 浏览 0 评论 0原文

我有大约 100 多个字段的表。其中有许多分散的日期字段(我怀疑大约有 8 个或更多)。我想要一个查询或 StoredProcedure 仅选择数据类型为日期或日期时间的字段。

这不是Project的要求,它只是我的分析工具。

我正在使用 MSSQL 2005,但它不必仅在 MSSQL 中。

I have table with about 100+ fields. There are a number of date fields in it scattered around (I am suspecting about 8 or more). I would like to have a query or StoredProcedure that selects only those fields whose data type is Date or Datetime.

This is not a requirement from Project, it will only be my analysis tool.

I am using MSSQL 2005 but it does not have to be only in MSSQL.

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

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

发布评论

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

评论(2

小霸王臭丫头 2024-12-17 01:19:48

您可以查询元数据:

select *
from information_schema.columns
where table_name = 'yourtable'
and data_type in ('datetime', 'smalldatetime')

此外,此 information_schema.columns 在其他数据库系统中也可用。

You can query the metadata:

select *
from information_schema.columns
where table_name = 'yourtable'
and data_type in ('datetime', 'smalldatetime')

Also, this information_schema.columns is available in other database systems.

你与清晨阳光 2024-12-17 01:19:48
select column_name
from information_schema.columns
where table_name = 'yourTableName'
and data_type like '%date%'
select column_name
from information_schema.columns
where table_name = 'yourTableName'
and data_type like '%date%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文