如何在 SQL 2000 中尝试解析?
我在旧的 SQL 2000 数据库中有一个存储过程,它采用 varchar 格式的注释列并将其导出为货币对象。 在设置此表结构时,假设这将是进入该字段的唯一数据。 当前过程的功能很简单:
SELECT CAST(dbo.member_category_assign.coment AS money)
FROM dbo.member_category_assign
WHERE member_id = @intMemberId
AND
dbo.member_category_assign.eff_date <= @dtmEndDate
AND
(
dbo.member_category_assign.term_date >= @dtmBeginDate
OR
dbo.member_category_assign.term_date Is Null
)
但是,现在正在将数据插入到该列中,该列无法解析为货币对象,并导致过程崩溃。 我无法删除“坏”数据(因为这是第三方产品),但需要更新存储过程来测试货币可解析条目并将其返回。
如何更新此过程,以便它只返回可解析为货币对象的值? 我是否创建一个临时表并迭代每个项目,或者是否有更聪明的方法来做到这一点? 我一直使用旧版 SQL 2000(版本 6.0),因此不幸的是无法使用任何较新的函数。
I have a stored procedure in an old SQL 2000 database that takes a comment column that is formatted as a varchar and exports it out as a money object. At the time this table structure was setup, it was assumed this would be the only data going into this field. The current procedure functions simply this this:
SELECT CAST(dbo.member_category_assign.coment AS money)
FROM dbo.member_category_assign
WHERE member_id = @intMemberId
AND
dbo.member_category_assign.eff_date <= @dtmEndDate
AND
(
dbo.member_category_assign.term_date >= @dtmBeginDate
OR
dbo.member_category_assign.term_date Is Null
)
However, data is now being inserted into this column that is not parsable to a money object and is causing the procedure to crash. I am unable to remove the "bad" data (since this is a third party product), but need to update the stored procedure to test for a money parsable entry and return that.
How can I update this procedure so that it will only return the value that is parsable as a money object? Do I create a temporary table and iterate through every item, or is there a more clever way to do this? I'm stuck with legacy SQL 2000 (version 6.0) so using any of the newer functions unfortunately is not available.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很抱歉做出新的答案,评论就足够了,但我缺乏这样做所需的权限。 关于您问题的答案,我只想补充一点,您应该谨慎使用上述 ISNUMERIC。 虽然它的工作原理与预期的一样,但它还将“1.3E-2”之类的内容解析为数值,奇怪的是,您无法将其转换为数值或金钱而不产生异常。 我通常最终使用:
Apologies for making a new answer, where a comment would suffice, but I lack the required permissions to do so. Onto the answer to your question, I would only like to add that you should use the above ISNUMERIC carefully. While it works much as expected, it also parses things like '1.3E-2' as a value numeric, which strangely enough you cannot cast into a numeric or money without generating an exception. I generally end up using:
检查 IsNumeric 可能会对您有所帮助 - 您只需返回零值即可。 如果您想返回“N/a”或其他一些字符串值,
我使用查询中的列创建了下面的示例。
第一个查询仅返回所有行。
第二个查询返回 MONEY 值。
第三个返回一个字符串值,用 N/A 代替非整数值。
Checking for IsNumeric may help you - you can simply return a Zero value. If you want to return a 'N/a' or some other string value
I created the sample below with the columns from your query.
The first query just returns all rows.
The second query returns a MONEY value.
The third one returns a String value with N/A in place of the non-integer value.