<bdo id='mpseG'></bdo><ul id='mpseG'></ul>
    <legend id='mpseG'><style id='mpseG'><dir id='mpseG'><q id='mpseG'></q></dir></style></legend>

        <i id='mpseG'><tr id='mpseG'><dt id='mpseG'><q id='mpseG'><span id='mpseG'><b id='mpseG'><form id='mpseG'><ins id='mpseG'></ins><ul id='mpseG'></ul><sub id='mpseG'></sub></form><legend id='mpseG'></legend><bdo id='mpseG'><pre id='mpseG'><center id='mpseG'></center></pre></bdo></b><th id='mpseG'></th></span></q></dt></tr></i><div id='mpseG'><tfoot id='mpseG'></tfoot><dl id='mpseG'><fieldset id='mpseG'></fieldset></dl></div>

        <small id='mpseG'></small><noframes id='mpseG'>

      1. <tfoot id='mpseG'></tfoot>

      2. SQL Server中如何确定不能转换为(decimal,float,int)的字段值

        How to determine the field value which can not convert to (decimal, float,int) in SQL Server(SQL Server中如何确定不能转换为(decimal,float,int)的字段值)
              <bdo id='RJfgk'></bdo><ul id='RJfgk'></ul>

                <tbody id='RJfgk'></tbody>

                <small id='RJfgk'></small><noframes id='RJfgk'>

              1. <tfoot id='RJfgk'></tfoot>
                <i id='RJfgk'><tr id='RJfgk'><dt id='RJfgk'><q id='RJfgk'><span id='RJfgk'><b id='RJfgk'><form id='RJfgk'><ins id='RJfgk'></ins><ul id='RJfgk'></ul><sub id='RJfgk'></sub></form><legend id='RJfgk'></legend><bdo id='RJfgk'><pre id='RJfgk'><center id='RJfgk'></center></pre></bdo></b><th id='RJfgk'></th></span></q></dt></tr></i><div id='RJfgk'><tfoot id='RJfgk'></tfoot><dl id='RJfgk'><fieldset id='RJfgk'></fieldset></dl></div>
                  <legend id='RJfgk'><style id='RJfgk'><dir id='RJfgk'><q id='RJfgk'></q></dir></style></legend>
                  本文介绍了SQL Server中如何确定不能转换为(decimal,float,int)的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 SQL Server 数据库.

                  I have a SQL Server database.

                  一个字段的值类似于

                   ID      VALUE
                    1      NEGATIF
                    2      11.4
                    3      0.2
                    4      A RH(+)
                    5      -----
                    6      >>>>>
                    7      5.6<
                    8      -13.9
                  

                  我想将 VALUE 字段转换为十进制,当然是可转换的字段.

                  I want to CONVERT VALUE field to decimal, of course convert-able fields.

                  1. 什么样的 SQL 语句可以做到这一点?

                  1. What kind of SQL statement can do this?

                  我如何了解转换时哪个值引发错误?

                  How can I understand which value is raising error while converting?

                  PS:我认为这可以解决 WHERE VALUE LIKE '[a-z]' 但如何添加更多过滤器,如 [-+ ()] ?

                  PS: I think this can solve WHERE VALUE LIKE '[a-z]' but how can I add more filter like [-+ ()] ?

                  推荐答案

                  Plain ISNUMERIC is rubbish

                  Plain ISNUMERIC is rubbish

                  • 空字符串、+-.都是有效的
                  • + 也是如此. 等等
                  • 1e-3 对浮点数有效,但对十进制数无效(除非您先将浮点数转换为十进制数)
                  • Empty string, +, - and . are all valid
                  • So is +. etc
                  • 1e-3 is valid for float but not decimal (unless you CAST to float then to decimal)

                  对于特别神秘但故障安全的解决方案,附加 e0.0e0 then 使用 ISNUMERIC

                  For a particularly cryptic but failsafe solution, append e0 or .0e0 then use ISNUMERIC

                  SELECT
                     ISNUMERIC(MyCOl + 'e0')   --decimal check,
                     ISNUMERIC(MyCOl + '.0e0')  --integer check
                  

                  所以

                  SELECT
                      ID, VALUE,
                      CAST(
                            CASE WHEN ISNUMERIC(VALUE + 'e0') = 1 THEN VALUE ELSE NULL END
                            AS decimal(38, 10)
                          ) AS ConvertedVALUE
                  FROM
                      Mytable
                  

                  这篇关于SQL Server中如何确定不能转换为(decimal,float,int)的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  sql group by versus distinct(sql group by 与不同)
                  How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
                  Count number of records returned by group by(统计分组返回的记录数)
                  SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)
                  • <tfoot id='urFO9'></tfoot>

                    <small id='urFO9'></small><noframes id='urFO9'>

                        <tbody id='urFO9'></tbody>
                      <legend id='urFO9'><style id='urFO9'><dir id='urFO9'><q id='urFO9'></q></dir></style></legend>
                          <bdo id='urFO9'></bdo><ul id='urFO9'></ul>
                            <i id='urFO9'><tr id='urFO9'><dt id='urFO9'><q id='urFO9'><span id='urFO9'><b id='urFO9'><form id='urFO9'><ins id='urFO9'></ins><ul id='urFO9'></ul><sub id='urFO9'></sub></form><legend id='urFO9'></legend><bdo id='urFO9'><pre id='urFO9'><center id='urFO9'></center></pre></bdo></b><th id='urFO9'></th></span></q></dt></tr></i><div id='urFO9'><tfoot id='urFO9'></tfoot><dl id='urFO9'><fieldset id='urFO9'></fieldset></dl></div>