使用 ODBC 查询 Access 2007 多值字段
我有一个 Access 2007 数据库,其字段之一使用“附件”数据类型(Access 2007 中的新增功能)。 该字段是一个神奇的“多值”字段,可以包含多个附件。
我希望能够使用单个 ODBC 查询轻松查看数据库中所有行的该字段的内容。 理想情况下,原始表的每一行应该恰好是一行,并且我希望所有附件作为单个数据库单元格返回。 在完美的世界中,可以使用单个 INSERT INTO 查询将该组附件重新插入到另一个表中。
我认为这可能是一个艰巨的任务,所以如果必须的话,我会满足于:
- 一个 SQL 查询,告诉我给定附件字段中的附件数量
或最坏的情况:
- 一个 SQL 查询,告诉我是否给定行中的附件是否为空。
我似乎在网上找不到任何关于多值字段的好文档。 也许它们太新了。
想法?
(PS 别费心告诉我多值字段是邪恶的。我已经知道了。我不是制作数据库的人。)
I have an Access 2007 database that uses the "Attachment" datatype (new in Access 2007) for one of its field. This field is a magical "multi-valued" field that can contain several attachments.
I would like to be able to easily see the contents of this field, for all the rows in the database, using a single ODBC query. Ideally, each row of the original table should be exactly one row, and I'd like all the attachments returned as a single database cell. In a perfect world, it would be possible to reinsert that set of attachments into another table using a single INSERT INTO query.
I think that might be a tall order, so if I have to, I'd settle for:
- An SQL query that tells me the number of attachments in a given attachment field
or worst case:
- An SQL query that tells me whether or not the attachments in a given row are empty or not.
I can't seem to find any good docs about multi-valued fields around on the net. Perhaps they're too new.
Thoughts?
(P.S. Don't bother telling me that multi-valued fields are evil. I already know. I'm not the one who made the database.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以使用 ADO,则无需在连接字符串中使用 OLEDB:Support Complex Data=True 连接到数据源并查询列:您应该获得一列类型
adLongVarWChar
(即MEMO
),其中值是以分号字符分隔的文件名。 因此,获取文件列表仅涉及简单的解析。也许可以使用 ADO 获取附件,但我还没有看到它完成。 使用
OLEDB:Support Complex Data=True
意味着您将获得一个adIDispatch
类型的列,即一个对象。 我不知道那个对象是什么(我希望它是一个ADODB.Recordset
但没有成功)。If you can use ADO then connect to the data source without using
OLEDB:Support Complex Data=True
in the connection string and query the column: you should get a column of typeadLongVarWChar
(i.e.MEMO
) where the value is the file names delimited by semicolon characters. Therefore, getting a list of files will merely involve a simple parse.It may be possible to get the attachments using ADO but I've yet to see it done. Using
OLEDB:Support Complex Data=True
means you will get a column of typeadIDispatch
i.e. an object. What that object is, I do not know (I hoped it would be a anADODB.Recordset
but no go).请参阅http://www.access-freak.com/tutorials.html#Tutorial07 获取一些信息,尽管他没有很好的屏幕截图或查询的 SQL。 他的网站的格式或可读性也不是最好的。
这假设您从 Access 2007 内部运行查询。如果您想通过 ODBC 运行查询,请参阅 http://groups.google.ca/group/microsoft.public.data.odbc/browse_thread/thread/d0ee29cc5e54e0fb
See http://www.access-freak.com/tutorials.html#Tutorial07 for some information although he doesn't have a good screenshot or SQL of the query. His website isn't the best formatted or readable either.
This assumes you're running the query from inside Access 2007. If you want to run it via ODBC see http://groups.google.ca/group/microsoft.public.data.odbc/browse_thread/thread/d0ee29cc5e54e0fb