将空 FoxPro 日期字段导入 SQL Server 2005
我正在将基于 FoxPro 的系统迁移到 SQL Server 2005 数据库。在 FoxPro 系统中,没有值的日期字段显示为“//”。当我使用 SQL Server 导入/导出向导时,这些空日期字段在生成的 SQL Server 表中被转换为“12/30/1899 12:00:00 AM”。
我的问题是:让 SQL Server 将这些空日期字段转换为 NULL 而不是 1899 年日期的最简单方法是什么?我没有运气深入研究导入/导出向导,并且我没有足够的 SSIS 包经验来知道该途径中的任何内容是否适合我的需求。
我将在不同时间导入多个表,因此解决方案越简单且可重复性越高越好。提前致谢!
I'm in the process of migrating a FoxPro-based system into a SQL Server 2005 database. In the FoxPro system, date fields without values show as ' / / '. When I use the SQL Server Import/Export Wizard, these empty date fields get translated to '12/30/1899 12:00:00 AM' in the resulting SQL Server table.
My question is: what is the easiest way to have SQL Server translate these empty date fields to a NULL rather than the 1899 date? I've had no luck in digging around the Import/Export Wizard, and I don't have enough experience with SSIS packages to know if anything in that avenue would suit my needs.
I'll be importing a number of tables at different times, so the easier and more repeatable the solution, the better. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然我很欣赏所提供的这两个建议,但我最终找到了更多“一劳永逸”的解决方案,而不是在导入每个表后对每个表运行查询。
我最终创建了一个 SSIS 包,并根据需要在源和目标之间插入了派生列转换。
例如,在派生列转换编辑器中,如果我有一个名为“comp_date”的日期列,并且我可以肯定地说 1910 年之前的任何日期都无效,那么编辑器中的前几列看起来像这样
: ,当我在包中配置它时,我只需要考虑一次 null 转换,然后随着更多的表被放入混合中,不断添加到包中。这让我得到了我需要的结果。再次感谢您的建议!
While I appreciate both the suggestions offered, I ended up finding more of a "one and done" solution, rather than running a query on each table after I import them.
I ended up creating an SSIS package and inserting a derived column transformation between the source and destination as needed.
For example, in the Derived Column Transformation Editor, if I had a date column called 'comp_date', and I can say with certainty that any date before 1910 is not valid, my first few columns in the Editor look something like this:
This way, I only need to account for the null conversion once when I configure it in the package, then continuously add to the package as more tables get thrown into the mix. This gets me exactly the results I need. Thanks again for the suggestions!
我将它们保留为 1899 年日期,并将其视为代码中的空日期。这通常是比插入空日期时间更好的方法。
I'd leave them as the 1899 date and treat that as an empty date in your code. It's usually a better approach than faffing with inserting null datetimes.
如果列中永远不会出现值 1899-12-30T00:00:00,您可以在插入后更新该值。
If the value 1899-12-30T00:00:00 is never to be expected in a column you can update the value after the insert.